Match empty lines in a file with 'grep'
grep and count empty lines like this:
grep -c "^$" myfile.txt
As \n
is considered end of line you need to use line start and line end "^$"
The regular expression to match the end of the line is $
, not \n
(since grep
works a line at a time, it ignores the newlines between lines).
grep -c '^$' myfile.txt