4 ms·
For some time I've been using both Awk and Perl for text processing, based on which offered the most convenient command for a given task. There are two (IMO) g
by pizza234 7y ago
For some time I've been using both Awk and Perl for text processing, based on which offered the most convenient command for a given task.
There are two (IMO) glaring omissions in Awk:
- using the captured group(s) of a regular expression
- slicing the arguments array
Mawk supports the first functionality, but it's inconvient.
Then at some point, I've found that virtually every task I do in my text processing via Awk can be done via Perl in a comparable way... and much more - including the two functionalities above - so I've ditched awk.
The only thing inconvenient is to type something like `perl -lane` as opposed to `awk`, but this can be aliased :-)
- Scarbutt 7y agoAWK can be learned much faster than Perl though.
- webreac 7y agoYes, but as soon as your awk script becomes complex, you need to switch to a more complete language like perl (or python or ruby). Switch slightly earlier and avoid learning all the subtelities of awk (the same applies to sed). You need to learn well one scripting language and to know most common use cases of sed, awk.
- Annatar 7y agoNo you don't. There is no reason to switch. I've written many full-blown programs in AWK and I see no reason to switch them to another language -- they're fast, portable and readable, with tiny memory requirements. It all comes down to mastery: someone who's mastered AWK will have no issues with a large AWK program and therefore will feel no urge to translate that program to another language. Large AWK programs are easy to maintain because the syntax is so small that the code is always intrinsically understandable.
- mcguire 7y agoYou don't so much learn Perl as develop the ability to emulate Larry Wall.
- shaklee3 7y agoNot to mention perl is significantly faster. I was fairly bummed when I learned this since it felt ask is no longer that useful.
- tannhaeuser 7y agoTry mawk. It's an incredibly fast awk implementation. If you're using gawk, setting LANG=C will make large awk programs with lots of complex regexpes run significantly faster as well.