4 ms·
Good question. I've been working with awk for several years now, and here's how I feel about it. AWK is old. 1977 old. Later versions that appeared (nawk and g
by babarock 12y ago
Good question. I've been working with awk for several years now, and here's how I feel about it.
AWK is old. 1977 old. Later versions that appeared (nawk and gawk are the most common) helped make it a smoother language, but it's still a pain. There are definite features you will be missing in an awk script:
- Any useful data structure slightly more complex than associative arrays. Try multi dimensional arrays, it's actually fun to do. Once.
- Any useful programming construct to help manage with complexity of scripts longer than a few hundred lines. No classes, no variable scoping, no namespaces in general. Not to mention an extremely permissive compiler.
- Any easy way to deal with the environment (other than text). Try sending http requests in awk, it can be a pain.
In 2015, if you need to write a script you should almost always prefer python/ruby over awk.
Now if you're asking whether you should learn awk? It comes in handy. There are a lot of awk scripts in the wild, and you may need to read them or edit them one day. Also, awk has a fun way of parsing input, which makes for very enjoyable one liners. Learning awk (and some complementary utilities like sed or find) turned me into a "oh, it can be done in a quick one-liner" kind of guy. Definitely recommended.
- a3n 12y ago> Also, awk has a fun way of parsing input, which makes for very enjoyable one liners. Yes, being able to casually toss off an awk (or sed) one-liner is a very convenient skill to have.
- davidp 12y agoYep. Need line 123425938039 of a gigantic file? [0] sed -e 'NR == 123425938039 { print; exit; }' < file Fast as hell and takes no memory to speak of. Google 'awesome awk' for goodies. [0]: Yes, this happens.
- eadler 12y agoWouldn't it be slightly easier to do something like sed -n 123425938039p file? To be fair, this one won't exit early.
- busterarm 12y agoI agree, but I get most of the same out of Ruby even if might be slightly less readable (or ugly Ruby code). It's nice that the mentality comes out of using certain languages though. also http://tomayko.com/writings/awkward-ruby http://tomayko.com/writings/awkward-ruby
- kazinator 12y agoSo you get an ugly program that requires a third party tool, rather than just a POSIX system. I would say that this solution then requires additional justification compared to the Awk no-brainer.