Posts Awk Usage
Post
Cancel

Awk Usage

Basic usage of CentOS command, awk
Find the total data sent by web server from access log

1
cat access.log | awk -F" " '{sum += $10} END {print sum}'

Where

  • -F ; field separator
  • ” “ ; space is the field separator
  • $10 ; 10th column, which is the bytes sent column in access log
  • sum += ; add up all the sent bytes and store in variable sum

seq

The returned number is in bytes, so divide sum by 1024 to get KB, divide again to get MB, divide again to get GB

1
cat access.log | awk -F" " '{sum += $10} END {print sum/1024/1024/1024}'

seq

This post is licensed under CC BY 4.0 by the author.