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 and shell scripting languages 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 09-07-2008 11:31 AM
debug aix 4.3 itik AIX 2 10-29-2007 11:56 AM
Debug an Awk Script mboro Shell Programming and Scripting 1 10-01-2007 07:05 AM
how to debug ramneek High Level Programming 1 09-19-2005 07:35 AM
disk space script debug - posted before bryan Shell Programming and Scripting 3 04-28-2005 08:50 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 1.00 average. Display Modes
  #1 (permalink)  
Old 11-05-2007
chella chella is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 75
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
  #2 (permalink)  
Old 11-05-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,930
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.
  #3 (permalink)  
Old 11-08-2007
drl's Avatar
drl drl is online now Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 712
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0