jonas jonas - 3 months ago 29
Linux Question

Delete empty lines using SED

I am trying to delete empty lines using sed

sed '/^$/d'


but i have no luck with it.
for example I have this lines:

xxxxxx


yyyyyy


zzzzzz


and i want it to be like:

xxxxxx
yyyyyy
zzzzzz


what should be the code for this?

Answer

you may have space/tabs in your "empty" line try this, see if it helps:

sed '/^\s*$/d'

Where \s matches any whitespace character.