3

I am decent with bash scripting and I am catching on to regex, and a little sed usage. Is learning awk still worth while with all the alternatives out there. Opinions?

1
  • Worthwhile from what perspective? Apr 29, 2010 at 3:59

5 Answers 5

10

The different alternatives exist, not because each can do the same thing as the other (although this is true for localized cases, or for full programming languages such as Perl), but rather because they can do different things.

sed is not very suitable for processing tabular data, and using pure bash for that is usually more pain than one would like. awk operates almost trivially on tabular data, and can also be used to write smallish state machines. Spend some time looking at the various awk solutions on Stack Overflow for some ideas as to what it can do.

0
3

I use awk all the time and avoid writing or using perl as much as I can. Perl wanted to do too much and became a general purpose language but unfortunately has an horrible and unreadable syntax, IMHO. Maintaining perl scripts that have been written by someone else is a pain and this tend to be true for our own scripts after a while too.

On the other hand, awk has a limited but on purpose scope and works well with it. It interfaces relatively well with shell scripting too, unlike perl.

As for bash being a survivor, I prefer ksh93 if you ask me.

1
  • 2
    +1 for using awk to avoid perl. Aug 13, 2012 at 14:23
2

I would hardly call Perl "dying", whatever other opinions you may hold about it

Since you made the Awk vs. Perl comparison, you might be interested in looking at the book Minimal Perl. It shows how Perl compares to various Unix/Linux command line utilities. It should give you enough information to make a more informed decision about what to study, regardless of your choice.

Personally, I think there are better choices than Awk, and would only learn it if it was clearly the best choice for my task at hand. But then again, I could say the same about a lot of things...

2
  • 3
    +1 for that first line. Apr 29, 2010 at 4:00
  • Given that Perl is no longer a language that younger programmers learn and that it is no longer included by default in many linux distributions, while AWK is part of the POSIX spec, can be learned in a day, and shows up regularly in any nontrivial bash scripting, it definitely looks like AWK will outlive perl.
    – saolof
    Oct 1, 2023 at 9:48
1

I still use awk occasionally - though I more frequently use Perl. If you don't want to learn Perl because you think it is dying (a view I disagree with, but you are entitled to your view), then consider Python instead. For plain text processing of columnar data, awk is excellent. For more general work, Perl or Python are excellent. After that, you are moving into heavy-duty systems programming and maybe C or C++ (or Go, or ...).

Bash is a very powerful shell. There are still things Perl can do that Bash can't. I still have to write code that will work other shells, so I have to be careful with what I use from the Bash feature set. Knowing it thoroughly will be good - but the other tools have their place too.

So, if you have the time to learn awk moderately well, or it is going to be easy for you because you are already adept at the components (extended regular expressions, C-like syntax), then it is an occasionally useful tool to have available to you. You might prefer to learn Perl or Python instead, though.

1

It depends on your comfort level.

I came to the shell via perl, so I am comfortable with using perl for complicated things.

However I find that the longer I am doing this, I want to do more and more complicated things in shell one-liners rather than deal with the overhead of a "proper" perl script. I find awk an invaluable tool for doing complicated things.

It never hurts to learn a little of everything, even if it is just enough for you to figure out that this particular tool does not fit into your ways of doing things.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .