The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can debug our UNIX shell script? psiva_arul UNIX for Advanced & Expert Users 3 4 Weeks Ago 07:31 AM
debug aix 4.3 itik AIX 2 10-29-2007 07:56 AM
Debug an Awk Script mboro Shell Programming and Scripting 1 10-01-2007 03:05 AM
how to debug ramneek High Level Programming 1 09-19-2005 03:35 AM
disk space script debug - posted before bryan Shell Programming and Scripting 3 04-28-2005 04:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-04-2007
Registered User
 

Join Date: Oct 2007
Posts: 73
Stumble this Post!
How to debug the awk script

Hi,
How can I debug an awk script?

I know that set -x can be used to debug a script. But this will not suite for awk scripts.

Can anyone help me?

Thanks in advance,
Chella
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-05-2007
Moderator
 

Join Date: Dec 2003
Location: /dev/florida
Posts: 951
Stumble this Post!
awk does not come with a built in debug option.

I have come across but never used awkdb:

AWK Debugger

Usually I just print out various messages or values of fields
to see what is going on.

If you are using gawk, you could recompile the source with
the debugging option turned on to print out the parse stack
information as gawk executes - but this will probably give
you far more information than you can use.
Reply With Quote
  #3 (permalink)  
Old 11-08-2007
drl's Avatar
drl drl is online now
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 508
Stumble this Post!
Hi.

This might help, at least in the early stages of developing an awk script:
Code:
#!/usr/bin/env sh

# @(#) a1       Demonstrate one debugging feature in [g]awk.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash awk

echo

awk --lint '
b == 1  { print " Found case for value of b is 1." }
' data1

exit 0
Producing:
Code:
% ./a1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
GNU Awk 3.1.4

awk: cmd. line:2: (FILENAME=data1 FNR=1) warning: reference to uninitialized variable `b'
awk: cmd. line:2: (FILENAME=data1 FNR=2) warning: reference to uninitialized variable `b'
awk: cmd. line:2: (FILENAME=data1 FNR=3) warning: reference to uninitialized variable `b'
However, most awk scripts are so short that it probably is not worth anyone's time to put in a lot of work doing a full debugger (well, it might be worth a grad student's time perhaps )

See info awk for the situations about which --lint will complain ... cheers, drl
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0