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 with a new line, right?
Please correct me if I am wrong.
You can use cap (^) and Dollar ($) in grep command to display empty lines in a file.
By Using [: space:]Grep's –v option will help print lines that lack blank lines and extra spacing that is also included in a paragraph form. You will see that extra lines are removed and output is in sequenced form line-wise. That's how grep –v methodology is so helpful in obtaining the required goal.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With