Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum of the column using Awk

Status
Not open for further replies.

Rvir

Programmer
May 16, 2007
18
US
Iam doing a awk on a column in file to find its sum. I have a process which generates a file and then this script runs and determines the sum.The source data which is used to generate the file is same all the time .Everytime i re run this process with same data i get different sum for each run.Please find my script below.
Begin
s+=$2
End
{
printf (" 7.2f\n" s )
}
The data in this column is decimal. The number records more than 700000 so its tough for me to find unprintable characters .Is there any way i can check unprintable characters and iam trying to think what could be other reasons. i did difference of last run file and prior file and found no difference in data in the column
 
What about this program instead ?
Code:
{s+=$2}
END{printf "%7.2f\n",s}


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
My mistake , this the code i use for calculating sum .

BEGIN {FS = "\t"}
{
s1 += $2;
}

END
{printf "COST AMT $%7.2f\n",s1 ;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top