The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




Thread: AWK script
View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 11-18-2008
Diabolist Diabolist is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 44
You list the working code, but not the code that's broken makes it a little hard to help.

I'll provide a simplified, working, example... maybe the problem will pop out at you?

My input file (called z.in):

Code:
10,ten
3,three
1,one
From the command line:

Code:
cat z.in |awk '{FS=","; sum += $1} END {print sum}'
13
Putting the awk junk in a script. Contents of z.awk:

Code:
{FS=","; sum += $1} END {print sum}
and the result:

Code:
awk -f z.awk z.in
13
Putting it all in a script. Contents of z.ksh:

Code:
#!/bin/ksh

awk -f z.awk z.in
And running it:

Code:
./z.ksh
13