Why does
grep -c \'^\\n\' myfile.txt
return 0 when there are empty lines in the file?
If there is an empty line, it starts
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
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 "^$"