General discussion

Locked

Matching blank lines

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

/^[<SPACE><TAB>]*$/

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?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Matching blank lines

by Point Man In reply to Matching blank lines

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

/$[<space><tab>]*$

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?

Collapse -

Matching blank lines

by jdogg In reply to Matching blank lines

All patterns must be surrounded by slashes

Collapse -

Matching blank lines

by argv[0] In reply to Matching blank lines

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

Collapse -

Matching blank lines

by jdogg In reply to Matching blank lines

Fair play - the POSIX classes work

Collapse -

Matching blank lines

by jdogg In reply to Matching blank lines

This question was closed by the author

Back to Linux Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums