I am trying to count records of particular format from a file and assign it to a variable. I tried below command
br_count=wc -l "inputfile.dat"| awk -F"|" '{if (NF != "14") print }'
but I amnot able to get it done. Please share me some idea how to get it done.
Thanks in advance
Try this:
grep -v "14$" inputfile.dat | wc -l
1 Like
count=$( grep -cv "14" infile )
--ahamed
Thanks balajesuri...
But I want that count to be assigned to a variable.
Please show me how to do show....
---------- Post updated at 10:57 PM ---------- Previous update was at 10:53 PM ----------
Thanks Ahamed...
I tested the above command. It given a count as 3, but the source file had 4 actually...
I am trying to count the records in a file having '|' in it.
The source file will look as below
Expected output : 4
Sorry for not conveying the requirement properly before
To assign the count to a variable obtained from guruprasadpr's solution, do this:
var=`grep -c '|' file`