Linked by Thom Holwerda on Tue 27th May 2008 13:08 UTC, submitted by Ward D
General Development AWK is one of the most common UNIX tools to process text-based data in either files or datastreams. Written by Alfred Aho, Peter Weinberger, and Brian Kernighan, AWK "extensively uses the string datatype, associative arrays (that is, arrays indexed by key strings), and regular expressions." ComputerWorld interviewed Alfred Aho.
Thread beginning with comment 315766
To read all comments associated with this story, please click here.
what an wonderful tool
by taos on Tue 27th May 2008 15:33 UTC
taos
Member since:
2005-11-16

So simple, yet so powerful.

Have you noticed that the program structure of DTrace in Solaris is also awk-like?

From dtrace_usenix.pdf :

" Each probe clause has the form:
probe-descriptions
/predicate/
{
action-statements
}
...
D uses a program structure similar to awk(1). "

It's just natural to write a program this way:
Match? Fire! Next.

RE: what an wonderful tool
by Doc Pain on Tue 27th May 2008 17:52 in reply to "what an wonderful tool"
Doc Pain Member since:
2006-10-08

Oh how I love these articles. =^_^=

So simple, yet so powerful.


I can only agree to that. Even today - why "even"? - awk is one of the tools I use. For example, I just wrote a simple awk script to convert a csv (comma seperated values) list file into a HTML and a LaTeX fragment. No big deal. Why? First of all, awk comes with my OS, I don't need to install anything (I'm using FreeBSD), no fat dependencies, and a great man page. And if you are familiar with C and know how to formulate regular expressions (as you need them), awk is a fast helper.

There are other great tools, little tools that simply do their job, just to mention a few: sed, grep, cut.

Have you noticed that the program structure of DTrace in Solaris is also awk-like?


Yes! :-)

It's just natural to write a program this way:
Match? Fire! Next.


By "match" you can attach actions to regex patterns of other conditions (e. g. line counters).

!/^#/ && (length != 0 || dings > 50) {
_____gsub($1 $2 bla bla bla);
_____pups = sprintf("zeux %dies %das %jenes", uhu, kram);
_____printf("bla", pups, furz);
_____dings++;
}
# And now for something completely different.

Reply Parent Bookmark Score: 3

RE[2]: what an wonderful tool
by whartung on Tue 27th May 2008 22:11 in reply to "RE: what an wonderful tool"
whartung Member since:
2005-07-06

There are other great tools, little tools that simply do their job, just to mention a few: sed, grep, cut.


AWK makes me hate cut.

Why oh why oh why can't cut compress white space just like AWK does. By default, AWK separates fields based on one or more white space.

1 2 <-- There's supposed to be several spaces here, but HTML eats them

is the same as

1 2

AWK treats the spanning white space as a single delimiter.

But oh no, not cut. Nope. If you use " " as a delimiter in cut, you'll get a field for every single space.

*sigh*

Even today, modern cut can't do that -- even as an option. So, I use AWK.

Just a pet nit...

Edited 2008-05-27 22:15 UTC

Reply Parent Bookmark Score: 2