Some Useful Gawk Scripts
Introduction to Gawk (tutorial): Available in powerpoint (gawk-tutorial.ppt) and pdf (gawk-tutorial.pdf) formats. These slides are from a lecture I gave to my fellow grad students using the AWK programming language for research purposes. AWK (including the extensions in the gnu version gawk) is a powerful tool that allows you to easily link together different systems allowing (for example) rapid prototyping, easy handling and manipulation of data, or generating plots.

In addition to the slides, I have put together some of the more useful awk scripts that I have made over my years as a grad student, in the hopes that you may find them useful.

Some Scripts: All of these scripts read from standard input and write to standard out. Most of them convert from some file or format type to another one and use the colon character ":" as a field delimiter (although this is specified separately for the most part).
  • array2html.awk: This script will convert from a array type file into a html table. It is pretty handy for putting your results up on the web, and I actually prefer using this script instead of coding in the bulky HTML table notation. Here is an example of the output generated from using it.

  • array2tab.awk: A really simple script to replace the colons with tabs.

  • array2tex.awk: This script will convert from a array type file into a TeX table for inclusion in papers. I hate making TeX tables with a passion, so now I always use this script to do it for me. Here is an example of the TeX output and what it looks like after rendering it with LaTeX into postscript and then into a picture.

  • arrayify.awk: Perhaps the most useful script in the bunch, this takes a list of data (as can be easily created by greping though all of your data files) and puts it into a big array (from which you can easily make tables and graphs. It's pretty simple, but a very versatile tool.

  • corrcoef.awk: This script will calculate the coeficient of correlation for list of x,y pairs. I am not possitive that it is correct, so if you want to use it for something important make sure that you verify the results.

  • decimal2binary.awk: A handy awk script to convert a list of decimal numbers into binary.

  • makeitemizelist.awk: This is another simple Tex authoring utility. It takes a set of lines and paragraphs and makes lists out of it.

  • prettyarray.awk: The array type files are really handy for using awk, sed, or perl on, but they are not that easy to read by humans. The prettyarray script will take an array type file and make a human readable text only table by evenning out the white space and adding some ASCII lines between rows and collumns. One feature is that the first collumn is used to determine weather or not to insert a horizontal spacer or not, so it is also handy for looking and lists of numbers too (For example if you put list example through the pretty array you get this).

  • transpose.awk: Transpose a text array. The ouput from the text array example will look like this .

  • unarrayify.awk: This is the inverse of arrayify.awk. It takes a text array and converts it back into list of data, which can sometimes be handy.

The author: If you have some gawk scripts that are really handy, I would love to make a good collection so please consider sending them to me. Hope this was useful to you -Tim Sherwood.