The UNIX and Linux Forums  

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 -->
  #1 (permalink)  
Old 11-18-2008
siba.s.nayak siba.s.nayak is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 166
AWK script

I have written an awk script. If i run it from command prompt with awk -f then it working fine. but when run the same statements in a script and named file as a1.awk and tried to run it awk -f a1.awk temp.txt > temp2.txt I doesn't work.

The script is like this
awk -F'|' '
BEGIN{

}

{ if($4=="1"){
print "*********" a[$3]

if( a[$3] < $6 ){
a[$3]=$7;
b[$3]=$2;
}
else if ( a[$3] == $7 ){
if( $9 == 1 ){
b[$3]=$2;
}
}
}
next;

}
END {
for ( x in b ) {
print x "|" b[x]
}
}

' temp1.txt> /var/tmp/temp2.txt

The above things works fine but when I put same thing in a script like
a1.awk
and run the script awk -f a1.awk temp1.txt > temp2.txt
No output is written to output file.
Please help me.