On Friday 27 January 2006 11:21, Eddie Chen wrote:
>Does any one knows how to do a trace on awk program???

If you have pgawk on your system, you can use the --profile command to at
least see how many times statements get executed.  Do:

pgawk --profile=awkprofile.out ...

and it will write your program to awkprofile.out with counts before each
statement, pattern, and function definition that tell how many times each was
executed, evaluated or called.  Patterns and conditional expressions have an
additional count written in a comment at the end of their line which
indicates how many times the pattern matched or the condition evaluated to
true.

I've never used that feature, I've always relied on inserting print statements
into the awk script itself to output the values of various variables so I can
see what is going on.  There's no real tracing facility (such as the shell's
-x option) in awk, so extra prints are usually the best thing to use.

You can put in prints that go to another file using redirection.  I usually
set up the filename in a BEGIN block so I don't have to type it each time:

        BEGIN   { DBG="myprog.dbg" }
        ...
        { print "Line: $0" >> DBG; ... }

Just be sure not to create any side-effects with your print statements!
        - MacK.
-----
Edmund R. MacKenty
Software Architect
Rocket Software, Inc.
Newton, MA USA

----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390

Reply via email to