If you need to get some text which is in file between two lines you could use awk for this. You may need it while analyzing access logs to fix some issue, for instance. Here’s how you could do it: awk ‘/2012:00:20:49/, /2012:00:35/’ access_log > output It’s a simple and convenient way.
All posts tagged awk
AWK: quick way to get squid users traffic usage
If you need quick and simple way to get squid users traffic usage you can use this script: #!/bin/bash awk ‘{ user = $8 traffic[user] += $5; } END { OFS = “tt” for (i in traffic) {printf “%s – tt size: %10.2f Mbn”, i, ( traffic[i] / (1024 * 1024 ) ) } }’…
AWK: getting last column value
If you need to get value of last column in awk you can use built-in variable NF which means the number of fields in record. awk ‘$(NF) !~ /-/ { print $0 }’ access_log Or next, if you need next to the last field. And so on. awk ‘$(NF-1) != /-/ { print $0 }’…