|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Code:
awk F"|^" '{ x += $256 } END { printf("%.2f\n", x) }' filenameDo you have example of your file |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|