4 ms·
For me the real advantage of awk, and I love me my awk, is that the entire reference manual is 10 pages long. http://man.openbsd.org/awk http://man.openbsd.org
by somat 3y ago
For me the real advantage of awk, and I love me my awk, is that the entire reference manual is 10 pages long.
http://man.openbsd.org/awk http://man.openbsd.org/awk
Other than that I agree, awk runs out of steam rather quickly. Shell runs out of steam fast as well(my cutoff for moving out of shell to a better language is the moment I need arrays.) But the killer feature of shell, the thing I wish was in more languages is pipes. The ability to flow one process into another process with a single character. I never did learn perl. but doing the equivalent to a pipe in python is a lot of awkward wrangling with subprocess and manually assigning streams. The way shell can pipe into and out of control flow is magical to me.
- qalmakka 3y ago> pipes In Perl you can just run commands using backticks or qx// and get their output, and so you can pipe them in any way you want: my @a = map { chomp; $_ } `ls -1 | sort | uniq` You can otherwise use `open` to spawn shells as if they were files, piping either on their left or right: open my $output, '-|', 'ls -1 | sort | uniq'; while (<$output>) { .. }
- dmd 3y agoIf you want to go beyond those 10 pages, the (also very short!) "official" book by Aho, Weinberger, and Kernighan ("The AWK Programming Language") is an absolute gem of technical writing. It is a joy to read.
- kamaal 3y agoWhile the book is awesome. And I guess there is a story some where that a programmer working with Aho even build CAD software with awk. Its often not an effort for the faint hearted, even to maintain. Without unit tests, exceptions, and myriad other features, you are doing too much of 'building universe to make apple pie' sort of work to get anywhere. Same with shell. You begin to give on it for non trivial work.
- theamk 3y agoI gave up on awk and always do perl one-liners. For basic stuff, they are about the same (perl _does_ have autosplit etc..) but every once in a while there is a slightly more complex task, like detect first unique field, work with json, shell quote, etc.. This is still trivial in perl, but turns out super ugly (or impossible) in awk. And if I have to fallback to perl periodically, why bother with awk at all? It probably made sense in the past, when machines were slow and awk was way more popular; but that does not matter now. Might as well go with more powerful option.