Every time I read about Awk, I feel very intrigued, but AFAIK, everything Awk can do, Perl can just as well. Is there a compelling reason to learn Awk if you know Perl beyond pure curiosity?
Every time I read about Awk, I feel very intrigued, but AFAIK, everything Awk can do, Perl can just as well. Is there a compelling reason to learn Awk if you know Perl beyond pure curiosity?
While you can write on one line of Perl anything that you can write in one line of Awk, the Perl line will be longer.
So for the simple tasks that you would do from the command line or in a shell script, you can usually save time when writing for Awk.
For complex tasks, where you need more complex control than the implicit loop of Awk and you also need to define various extra variables besides those pre-defined, Awk is no longer more concise.
Then obviously Perl or other scripting languages become more convenient.
The Awk variant had 350 bytes, while the identical Perl variant had 450 bytes.
The extra length in Perl was due to "$" prefix on all variables, an extra "split()" and an extra "while()", which were not needed in Awk.
For slightly simpler versions of those scripts executed as one-liners, the difference in length was even much more in favor of Awk, because Perl needed extra command-line options to execute the script in the command line, while that is the default behavior of Awk.
So don't bother as long as Perl is ubiquitous.
It is installed everywhere pretty much so it's nice to know. I keep thinking the same since I know Perl.
Well, that's what I meant by "pure curiosity". ;-) Which is a perfectly valid reason to learn a language, of course, possibly the best reason one can have.
But I guess when I need a quick and dirty one-shot script, I'll stick to Perl for the time being. It's not officially standard like Awk, but it is available in the default installation of pretty much every open source Unix-like system I use except FreeBSD where it's one of the first packages I install.
Hypothetically, Perl is also available on systems that are not very Unix-like, such as OS/400 (or "IBM i" as it is called these days, apparently) or VMS. (Hypothetically in the sense that I have never had direct contact with one of these systems and have no expectation I ever will, sadly. ... Well, maybe I should count myself lucky - either way, I will probably never know for sure.)
I just about never have to refer to the man page. I also found that I can go for months without writing any Awk and then knock out a quick script without having to relearn anything.
I'll concede that there are things for which Awk just isn't powerful enough and perhaps I was never that good with Perl to begin with, so if you're already well versed in Perl YMMV