New Eyes on an awk script

David Bandel david.bandel
Mon Nov 15 07:27:31 PST 2004


On Sun, 14 Nov 2004 11:15:37 -0800, Shawn Tayler
<stayler at xmtservices.net> wrote:
> Would one of you more knowledgable type show me the stupid mistake I am
> making with the following awk script?  I have been banging my head against
> the "syntax error" wall for a while now.

Been a while since I used awk (I normally use Perl now), however, I would try:

if ($NF == 9) { ... }
This interprets the variable NF and takes its value rather than
testing to see if NF is equal to 9.

> 
> BEGIN { FS = "," }
> ++x
> if ( NF == 9 )  { print x","$1","$2","$3","$4","$5","$6","$7","$8","$9",NA" }
> if ( NF == 10 ) && ( $9 == $10 ) { print x","$1","$2","$3","$4","$5","$6","$7","$8","$9",NA" }
> if ( NF == 10 ) && ($9 != $10 ) { print x","$1","$2","$3","$4","$5","$6","$7","$8","$9","$10 }
> if ( NF == 8 ) { print x","$1","$2","$3","$4","$5","$6","$7","$8", , " }
> 
> I keep getting a syntax error on the if statement.

Ciao,

David A. Bandel
-- 
Focus on the dream, not the competition.
            - Nemesis Air Racing Team motto


More information about the Linux-users mailing list