Hi,
I have a pipe seperated file
I want to write a code to display count of lines that have 20th field not null.
nawk -F"|" '{if ($20!="") print NR,$20}' xyz..txt
This displays records with 20th field also null.
I would like output as:
Hi,
I have a pipe seperated file
I want to write a code to display count of lines that have 20th field not null.
nawk -F"|" '{if ($20!="") print NR,$20}' xyz..txt
This displays records with 20th field also null.
I would like output as:
nawk -F'|' '$20!="" {tot++} END{print tot}' infile
awk -F"|" '$20 { NN++; next } { N++ } END { print "Null: " N " Not Null:" NN }' file1
Thanks, this works fine.
Sir can you please explain this.
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