We help IT Professionals succeed at work.

Should I learn AWK for text manipulation?  Or just skip and go straight to Python, Ruby, or Perl?

ThoughtProcess
ThoughtProcess asked
on
I've been doing a lot of text manipulation lately, and for most of my day-to-day tasks I've been able to clunk along using grep and sed with the appropriate pipes.  On occasion I'll write a quick one-off C/C++ program if I can't figure out how to parse a file using those tools.

Lately I've had to process some more sophisticated files (such as performing pattern matching across multiple lines), and I'm finally coming to grips with the fact that I need to learn a text manipulation language.  It will be a welcome addition to my mental tool belt.

I know there are a host of contenders out there (Python, Ruby, Perl, and AWK come to mind).  AWK seems nice because it's purpose-built for text manipulation.  At the same time, I understand that Python or Ruby can do text manipulation *and* build sophisticated applications.  And then there's Perl, which seems so massive and powerful that I'm not sure how to weigh it against the other options.

Is there any significant reason to learn AWK *in addition to* or *instead of* one of these other languages, if I just want to do text processing?

Thanks!
Comment
Watch Question

As you've mentioned, PERL is sufficient.. All others are like subsets of it. And what you can do in awk can be done in perl with almost same or even less code

Commented:
it's question like
'if I learning bash should I know ls command', the answer is no, you can use double <tab> pressing when you move to other directory.

awk it very simple 'pipe' text processor, it is very useful, but you can use perl to do the same things
perl is very big, powerful script language.

If you only need to count some statistics, max, min, little calculation on coma separated files awk is enough and one line command.
there are a lot of perl libraries to allow you build big applicatoins, awk does not have any, it is only to simple line reading.

awk you will lern in 1h

I love bash.
rgds
rumi
HonorGodSoftware Engineer
Commented:
One thing to consider is:
- how often you will be reading the code you write

Since you have used RegExp (in sed), you know how challenging they can be.

I got pretty good at Perl, but when I wasn't using it every day, my ability to read, and understand my own code suffered.

I find Python much more readable, and therefore much easier to understand... even months after I wrote the code.

This can be especially true if your code might, or will be seen/read by others.
Top Expert 2007
Commented:
If you are writing one liners, then awk is quite sufficient.  While you can write quite complex scripts with awk, you are better off using Perl, Python or Ruby.

Also remember that Perl borrows heavily from awk, so the syntax for common tasks is very similar.

ozo
Most Valuable Expert 2014
Top Expert 2015
Commented:
Sometimes awk is available where perl is not, (though that is becoming increasingly rare)
Some small tasks may run faster in awk.
There is less to learn for awk, (although if you only use the subset of perl that works like awk, it's not that much difference)

Author

Commented:
Thanks for the info, guys.  I think I'll pick up AWK for my immediate needs, and then focus on a more full-featured, high-level language as time allows.  It sounds like the similarities between AWK and the other languages make the transition easier than I expected.
HonorGodSoftware Engineer

Commented:
Thanks for the assist & points.

Good luck & have a great day.