extract awk scripts from The AWK Programming Language
The AWK Programming Language is the book authored by the authors
of AWK itself, Alfred Aho, Brian Kernighan, and Peter Weinberger. It contains
many short awk langauge and awk script examples throughout. It makes them
available for download from the
book's homepage, all consolidated in a single text file. Find and download
that file. It's at the link entitled "as text (120Kb)". The name of
the file is awkcode.txt. The number of individual snippets of awk code in that
file is over 200, with a total line count of over 3000.
Create a containing directory, cd into it, download awkcode.txt, and place it into that directory. You could download it from the homepage with a graphical browser via the provided link, or directly from the command line:
wget http://cm.bell-labs.com/cm/cs/who/bwk/awkcode.txt
== Note: as of May 2015 I see the book's homepage has gone away. Please obtain awkcode.txt from the class unix server instead. ==
Upon receiving the file, you will want to break it out into the 200 individual snippets one per file. That way, you can use each file by executing it as a separate awk script. But this method of delivery, 200 different snippets on 3000 consecutive lines of a single text file, is unusual. How do you "unzip" a text file? The authors have provided a way to do it, by using awk itself on awkcode.txt. At the very beginning awkcode.txt there is a 2-line awk program that will do the job. Study that program, and the line structure within the file (upon which the method depends). Figure out how to invoke the code, against the text, to produce the snippets in 200+ individual files.
