![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| using awk to count no of records based on conditions | aemunathan | Shell Programming and Scripting | 13 | 06-14-2009 07:41 AM |
| exclude records with null fields | praveenK_Dudala | Shell Programming and Scripting | 2 | 03-01-2009 09:54 PM |
| Count records in a zip file | tekster757 | UNIX for Dummies Questions & Answers | 3 | 09-24-2008 04:19 PM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 01:15 PM |
| finding null records in data file | dsravan | Shell Programming and Scripting | 3 | 01-09-2007 03:46 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Awk to Count Records with not null
Hi, I have a pipe seperated file I want to write a code to display count of lines that have 20th field not null. Code:
nawk -F"|" '{if ($20!="") print NR,$20}' xyz..txt
This displays records with 20th field also null. I would like output as: Quote:
|
|
||||
|
Code:
awk -F"|" # Field separator is |
'
$20 { NN++; next } # if $20 is defined (not null) add 1 to NN (not null) variable, and go to next record
# (after a "next" no rules are evaluated, we go back to the start, for the next record)
{ N++ } # We only get here is record 20 is not defined (is null) so add 1 to N (is null) variable
END { print "Null: " N " Not Null:" NN } # finally, print both counts
' file1
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|