I want to display the number of empty lines in a file. I guess i should use 'grep'...but how..
10x for those who'll help.
Nah, use awk.
# of empty lines
grep -n ^$ filename | wc -l
lines that are empty
grep -n ^$ filename | tr -d :
...
to remove all empty lines
grep -v ^$ filename >newfilename
1] you can use the egrep command like
egrep [a-z,a-Z,0-9] testfile.txt >> new.txt
[ it will extract the all rows but except the blank rows]
2] then take the line count of the bth the files using
wc -l testfile.txt -- [ say 15 with 5 blank lines] and
wc -l new.txt [ it will give you only 10 lines]
rm new.txt
now substract the both values you will get the total blank values in your file
Hope it will help you
Regards,
Swapneel
nawk '/^$/ {n++} END{print n}' yourfile
Thanks for the help, this also works:
grep -ca ^$ filename
10x especially for stobo �s reply.