Discussion Locked

Matching blank lines

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am trying to match all blank (including null) lines in a text file. Using sed the regular expression is:

/^[]*$/

which should match 0 or more occurrences of a space or tab followed by the end of line. I have even seen this expression quoted - a colleague has used the same expression in an ex command in vi and both of us cannot get it to work.

Any ideas?

5 replies

by point man

Possibly within vi your friend was including the final '/' which shouldn't be included. This works for me under vi:

/$[]*$

Where the space is pressing your space character and the tab is pressing the tab character.

grep -c '^[ ]*$' ./httpd.conf

Where the whitespace is pressing the space and tab characters.

Does this help?

by argv[0]

As I think expression:
^[[:space:]]*$
be better because of all whitespaces (' ', '\t' and '\r') will be matched.
It's impotent especially if your text coming from DOS/Windows

This discussion is closed to new replies.