Sunday 20 November 2011

Tip: Grep for non-matching lines

I've been working on a lot of .config files lately and I've found the following grep command very handy.

grep -v -E '^\#|^$' test.conf

Basicaly returning all lines that don't begin with  # (comments) and blank lines. It's a quick way to see whats configured in the conf file.

The -v is the invert match, to show non-matching lines.
The -E is for extended regular expression.
The ^\# regex of line beginning with #
The | regex for OR
The ^$ representing empty lines
And of course the file you which to perform the search on.

No comments:

Post a Comment