31 August 2011

Wish I had learned this

John D. Cook reviews Peteris Krumins's new e-book, Awk One-Liners Explained. The need for one-line programs accounts for the long-tail popularity of an old command-line language like Awk. As Cook writes,

If something takes more than one line of awk, I probably don’t want to use awk.


My copy of Aho, Kernighan, and Weinberger has this one-liner pencilled on the back page. I've never found a simpler way to find the longest pathnames in a directory tree:


find . | awk '{print length($0) " " $0}' | sort -r -n


As I remember, I once prototyped a COBOL pretty-printer in Awk. That was more than a one-liner.

No comments: