It's been a while since I've used awk and like all things that are un-used, they tend to get a bit rusty. Today I needed to parse a column out of a text file and the formatting was very uneven to the put that cut wasn't going to.. well.... cut it. Bad pun aside, I pulled out the man page for awk to remind myself of how it worked and a few minutes later came up with this little gem
awk 'BEGIN { FS="[ ]*" } { print $4 }' server.log
No surprise, the BEGIN block is executed once at the beginning and the next block is executed for every single line of input. The line of input is split according to the FS regular expression so it follows that $4 prints the 4th column of text (awk arrays start at 1 and 0 refers to then entire string) found in server.log.
Done? not quite. The output contained a few more lines than I was interested in. No problem, I just found a pattern to identify the lines I wanted that would exclude the lines that I didn't want and modified the script to this.
awk 'BEGIN { FS="[ ]*"} / 1:/ { print $4 }' server.log
The whole experience reminded me of what I'd discovered long ago, awk is a great little tool for quick little data processing jobs. And, it's not so bad at larger ones either.