Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-15-2013
Registered User
 
Join Date: Aug 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Sum of 286th column using awk in a file

Hi,

I am using the following code to find the sum of the values of column 286 in a file. It will have the Decimal values with the scale of 2. Delimiter is '|^'


Code:
cut -d'|^' -f286 filename|cut -c3-| awk '{ x += $1 } END { printf("%.2f\n", x) }'

There are around 50k records in this file and for few files this code is running fine but for some files the Sum value is not correct. This is verified by the summing the data loaded in the table from the file.

Let me know if any changes are to be made to the above code.

Thanks,
Jram.
Sponsored Links
    #2  
Old 02-15-2013
Jotne's Avatar
Registered User
 
Join Date: Dec 2010
Posts: 522
Thanks: 45
Thanked 98 Times in 91 Posts

Code:
awk F"|^" '{ x += $256 } END { printf("%.2f\n", x) }' filename

Do you have example of your file
Sponsored Links
    #3  
Old 02-15-2013
Registered User
 
Join Date: Feb 2013
Posts: 36
Thanks: 0
Thanked 19 Times in 14 Posts
Are you sure about the field delimiter? When using your above code, GNU cut tells me cut: the delimiter must be a single character

The other cut which I have here says: cut: bad delimiter
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to sum multiple column output with awk ? rveri Shell Programming and Scripting 2 12-24-2012 04:34 AM
Read first column and sum values in second column using awk kidncute UNIX for Dummies Questions & Answers 15 03-13-2012 05:51 AM
how to count number of rows and sum of column using awk pistachio UNIX for Dummies Questions & Answers 2 05-20-2010 12:55 AM
help sum columns by break in first column with awk or sed or something. syadnom Shell Programming and Scripting 6 02-01-2009 04:23 AM
Column containing sum using awk baconbasher UNIX for Dummies Questions & Answers 4 07-25-2008 12:16 PM



All times are GMT -4. The time now is 11:17 PM.