|
|||||||
| 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
|
|||
|
|||
|
Why sum of recs in awk don't match total rec count?
I'm using awk to determine if a field starting in position 604 for length of 10 is not equal to ALL spaces. It's searching several files which are in the current directory. The below awk indicates that there are 84 records on all files where this field IS NOT equal to ALL spaces ( there are 10 spaces between the quotes). Code:
awk 'substr($0,604,10)!=" " {print substr($0,604,10)}' LPM_BENE_BATCH_*.txt | wc -l
84I then want to run the negate of the above to validate against the total record count of all files. The below awk indicates that there are 444 records on all files where this field equals all spaces. Code:
awk 'substr($0,604,10)==" " {print substr($0,604,10)}' LPM_BENE_BATCH_*.txt | wc -l
444But when I count all records on all the same files the above 2 awk commands are searching I get 1 less record then when I sum the above counts (84+444 = 528). Code:
wc -l LPM_BENE_BATCH_*.txt 527 total What are some factors that could cause my total to not match? |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
wc counts the number of newlines. If one of the files doesn't end in a newline, that would explain the discrepancy, since awk would add the missing newline when it prints that record.
Regards, Alister |
| The Following User Says Thank You to alister For This Useful Post: | ||
mjf (02-26-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks for the explanation alister! I was able to find the offending line missing the newline char.
Last edited by mjf; 02-26-2013 at 08:45 PM.. |
| 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 |
| sum using awk with pattern match | sol_nov | Shell Programming and Scripting | 2 | 08-31-2012 03:45 AM |
| awk and count sum ? | sabercats | Shell Programming and Scripting | 5 | 05-11-2012 10:44 PM |
| Total Count using AWK | sraj142 | Shell Programming and Scripting | 8 | 08-16-2011 04:19 AM |
| awk count characters, sum, and divide by another column | peromhc | Shell Programming and Scripting | 1 | 06-14-2010 06:48 PM |
| 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 |
|
|