AWK related software
There exist software tools other than AWK that a programmer may use instead. Some of them are easier to use for specific tasks, others may run faster than AWK does. Anyway, it's not bad to know that AWK is not the only porgrammable tool for filtering and processing data; it's also fun to try to solve specific problems with more than one ways and compare the results for effectiveness, resource usage, clarity and beauty.
sed stream editor
sed
is a stream editor, means that sed
is not an interactive editor where the writer is seating in front
of a terminal, writing and editing some text.
sed
is a batch program that can take some directives and then
reads data, filter them according to those directives and prints the
resulting data, without any user intervention while processing the data.
The GNU sed
manual is very instructive, but there are also many
good books about sed
, e.g. the classical
"sed & awk"
by Dale Dougherty and Arnold Robbins.
sed
has many things in common with AWK, e.g. regular expressions.
Almost always, one can use AWK instead of sed
, but sometimes
doing so may be an overkill.
Check this out!
In my computer, the size of the gawk
executable is about nine times
the size of the sed
executable.
Another significant reason for not using AWK where you can use sed,
is that in many cases sed
directives may be more clear than the
correspondng AWK program, to carry out the same task.
Let's say we want to filter our data as follows:
We want to substitute all occurences of "@
" symbol with the
"#
" symbol, but only in lines begining with a capital letter.
Here is the sed
approach:
sed '/^[[:upper:]]/s/@/#/g'
The corresponding AWK apporach is:
gawk '/[[:upper:]]/ { gsub(/@/, "#") } { print }'
After running the above on a huge amount of data, I've found out that
sed
may run up to 2 times faster than gawk
!
mawk
runs faster than gawk
, but lacks the
[[:upper:]]
pattern for matching UTF-8 capital letters.
The Perl programming language
To be honest, I don't know Perl, but it's more than a sure fact that Perl is a very popular language. There exist innumerable shell scripts that use Perl scripts inside, and there exist even more application programs based on Perl. The fact that Perl uses regular expressions and is programmable, just like AWK does, makes the two languages to be similar and competitive.
There is no answer to the question who is better, Perl or AWK, as there is no answer to many other similar questions, e.g. Apache vs NGINX, Linux vs FreeBSD, GNOME vs KDE, LAMP vs MEAN etc. I prefer AWK, but as I said earlier, I don't know how to use Perl effectively because I don't know Perl at all. Many of my colleagues prefer Perl, others use both of these two magnificent languages.
The truth is that the majority of AWK programs are more readable than the correspondig Perl ones. In fact AWK happens to be one of the most elegant software tools ever written, while it's a known joke that Perl programs are write-only programs. To be serious, Perl is an extremely poweful software tool standing side by side with AWK in the programmer's quiver.