I am trying to delete empty lines using sed:
sed '/^$/d'
but I have no luck with it.
For example, I have these lines:
xxxxxx yyyyyy zzzzzz
and I want it to be like:
xxxxxx yyyyyy zzzzzz
What should be the code for this?
To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
We can remove blank lines using awk: $ awk NF < myfile.
You may have spaces or tabs in your "empty" line. Use POSIX classes with sed
to remove all lines containing only whitespace:
sed '/^[[:space:]]*$/d'
A shorter version that uses ERE, for example with gnu sed:
sed -r '/^\s*$/d'
(Note that sed does NOT support PCRE.)
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