delete blank lines

I had a need to delete blank lines from the output. And I tried this from my previous post[1].
sed '/^$/d'

The above sed works fine, if the lines are truly empty. But not for lines which might look empty, but contain invisible characters like space or tab or similar.

We can eliminate lines with spaces or tabs.
sed '/^[ \t]*/d'

Some other commands which do the same

grep -v '/^[ \t]*/d'

grep -E '\S'

grep '[^[:blank:]]''

But I'm not quite sure of all other invisible chars.


[1] sed quick reference

No comments:

Post a Comment

most viewed