Sum of 286th column using awk in a file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Sum of 286th column using awk in a file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-15-2013
Jram Jram is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 September 2013, 3:18 AM EDT
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
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
Thanked 216 Times in 204 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
user8 user8 is offline
Registered User
 
Join Date: Feb 2013
Last Activity: 24 April 2013, 10:34 AM EDT
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
Closed Thread

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 01:58 AM.