awk: script created in 1988 still works

I have been using bash recently, and it turned out that some powerful regex options are available via awk.  I looked around and found a book written by the original awk authors Aho, Weinberger, and Kernighan:“The AWK Programming Language”

I found a graph in Chapter 6 that called my attention and I wanted to reproduce it:

Chpt6_graph

So I copied the code from this old book and soon found out that parts of the code were not copied, parts were copied incorrectly (instead of $ y got 5, or instead of } I got ), etc), so I set off to debug it.

Finally I got it to work and after making up some entries for the data, there are two files you need to run it.  Only docx format is allowed in wordpress, so the files below have the extension docx but they are just plain text files.

graph1 (code)

data

You need to run them as shown below, i.e. either rename them to have no extension or copy the text to some files without extension.

awk -f graph1 data

So I got the following:

Chpt6_NEWgraph

Notice that I used cygwin so I can run it in windows: https://cygwin.com/install.html

Additional reference:

AWK -wiki

 

 

 

Advertisements

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: