Linux.com

Re:A very nice article

Posted by: Anonymous Coward on January 17, 2006 11:48 AM
I think there comes a point where awk really is a hard language. Hard to maintain but also hard in the sense that you have to do some pretty arcane stuff to get it to do certain things. I studied a book on awk, and you are right - it really would take time and effort to learn all of its features. Time and effort that may or may not pay off.

awk has a different logic to it that other procedural languages do not have (it's a bit like a cross between C and sed). The article mentions all the work that awk does for you. This is all related to the logic it uses. awk is designed to read a file which is somehow structured as records of delimited fields. awk then gives you the ability to conditionally execute different blocks of code on every record. Therefore awk is worth considering for any situation that fits that pattern. Very often awk will do the job nicely. Sometimes it just gets too `awk-ward'.

Where awk excels is simple stuff like `ls -l | awk '{print $5,$9}'`. awk is also really useful inside shell scripts where a half dozen lines of indented awk code can be mixed in with shell code and sed code to great effect. I would typically use awk many times a day from the command line or in simple scripts, and 90% of it is simple one-liners. So I guess what I am saying is if you use awk at all, you are probably getting excellent value from it right now. In my case, it took me a year before I really understood what awk was doing at all (new to Unix), and since that time I have gradually extended my use of it one tiny feature at a time.

grep, sed and awk are now my bread and butter. I am glad they are there.

#

Return to CLI Magic: Learn to talk awk