Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug an AWK script

Tags:

scripting

awk

What are the tips for debugging any AWK script?

like image 525
Vijay Avatar asked Jan 22 '10 10:01

Vijay


2 Answers

Use the print statement in your code to print out values of variables/return values and so on. If you are using gawk, you can use the -W dump-variables[=file] option to dump variables out to a file for debugging.

Also, the option -W lint[=value] might be of interest. See the documentation for more. Other versions of AWK, such as pgawk provides profiling.

A page of the sed/awk book on debugging for your reference.

like image 152
ghostdog74 Avatar answered Nov 19 '22 03:11

ghostdog74


There is now this page: Debugger Invocation - The GNU Awk User's Guide; mentioning an invocation like:

 $ gawk -D -f getopt.awk -f join.awk -f uniq.awk inputfile

... which should otherwise spawn a shell interface; but I don't have the --debug/-D switch on my GNU Awk 3.1.7, unfortunately..

EDIT: Found some more about this:

awk.info » New AWK debugger

Arnold Robbins writes in Feb 2010..
The distribution is available at http://www.skeeve.com/gawk/gawk-3.1.7-bc-d.tar.gz ...
This version is the same as 3.1.7, but with a new execution engine and a debugging version of gawk named, rather imaginatively, "dgawk"...

And then:

GNU Awk: This is Not Your Father's Awk | Dr Dobb's

Awk-level debugging with a debugger that is similar to GDB, the GNU debugger. This first became available with gawk 4.0 (released in 2011) as a separate executable, but it is now built-in to the regular gawk executable.

So that explains why I don't have it ... time to build from source, I guess :)

like image 5
sdaau Avatar answered Nov 19 '22 02:11

sdaau