What are the tips for debugging any AWK script?
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With