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

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}'