AWK may not be the first language that comes to mind when you need to write a program, but its flexibility may surprise you. The article is at LinuxJournal.
AWK may not be the first language that comes to mind when you need to write a program, but its flexibility may surprise you. The article is at LinuxJournal.
I always liked awk. You can learn it in a day or two and use it to write complex filters with rather elegant code. For more complex tasks, you combine it with shell scripts and other command line utilities in the spirit of old-time Unix shell programming. Then perl came along with its kitchen sink mentality, and the scripts became so dense that it was hard to read your own code (let alone someone else’s) a few months later after you’d gone back to programming in C or C++… not sure newer is better in this case.
Perl is evil. Nothing more need be said about it.
Python is okay, but annoyed me with it’s little inconsistencies.
Ruby is king for code consistency and readability, the online documentation sucks though.
In the timeline awk precedes all of these. It’s okay but you’d almost be better off learning python or ruby to do anything serious.
I like awk.
http://awk.geht.net/htdocs/README.html
> Perl is evil.
This sounds like a flamebait. I know Perl and Python fluently, as well as some Ruby, and have always come back to Perl (real OO applicatione with thousands of lines of code). Summary of my experience would be “Perl is power”
AWK is “Perl of the eighties”. There’s nothing in it you can’t do with Perl and in the same amount of code. Instead of learning it in the A.D.2003, you would be far better off learning the equivalent subset of Perl or python.
Python is less writable, but more readable.
perl is more writable and far less readable.
I have no experience is Ruby, but from what I have seen, it is more writable than python, and more readable than Perl.
all have about the same amount of Orthangonality, not to much, but just enough to make it nice to code in.
As with everything, there is more than one way to do it.
Awk can be great in some situations, just like sed can be very handy. But sure Perl can do whatever those two can do, and a whole lot more. And then there’s python and ruby too.
Just use whatever you think is good for the job. Use whatever you like, and be happy we’re in an open source culture that has plenty of choice to offer!
well, it is a bit more complicated than use what ever you like.
I mean, would you use C or C++ for CGI?
there are some languages that are much better at things than others, though the languages might be close in abilities.
The only time I’ve ever used awk is to do things like this:
ls -l | awk ‘{print $1;}’
Which would give you the first column of output from ls. I’ll usually through things like that into a script along with other code when I need to work on columns of data.
I love AWK. It’s like having a C interpreter.
Because it was written by a great stylist, Brian Kernighan, it is easy to read — unlike Perl.
An even better version of AWK is TAWK, by Thompson Automation Systems. It supports multi-dimensional arrays and has a compiler. It is unfortunate that GAWK has not emulated these features, yet.
I’ve been a big fan of awk for years. Use it constantly. Mostly for simple filters, or some quick code generators. The things that awk gives “for free” eliminate enough cruft and boiler plate to make it easier to work with out of the box than the advantage of vastly more powerfule Perl/Python.
It’s a specialized language, but its specialty covers a wide array of activities that I need to do.
What is interesting is that many folks use it for simply grabbing columns of text, and awk seems to do this much more easily that cut(1).
As a quick nit to the article, while its a viable script, I think the Perl formatting techniques may have given it an edge in this case, and he goes thruogh a lot of effort that could perhaps more easily be solved with the join(1) command.
Python: Just started using it, but I like it. I am actually having fun with it! Great readability and great for RAD stuff. (Glade mixed with Python is great).
Perl: Used it for years and always hated every minute of it. Nothing else to be said, Perl is dead to me with Python/PHP combo.
AWK: Never wrote full fledged programs with it, just one off command line things. useful, never used it more than that.
The fanciest thing that I’ve done with AWK is to make a chart in LaTeX out of the entries in /usr/X11R6/lib/X11/rgb.txt. I turned entries like
“255 239 213 PapayaWhip”
into a line of a table with the color name (PapayaWhip here) a box colored with the appropriate RGB values (255 239 213 here).
The PDF resulting from the LaTeX file is almost as useful as the xcolorsel app.
personally, I would rather like to have records more than parallel arrays.
I mean, there are nice things you can do with parallel arrays, like Linear algebra, etc. but if you are making a data intensive program, records are so much better.