Reputation: 3165
I want to grep all none #
comment lines,
Although I can use grep -v -E '^\s*#'
, I want to know if there is another way not using -v(revert) option.
#a comment line from a tab
abcd
xx
#a comment line from head
#a comment line from a space
I tried many patterns but failed:
grep -E '^\s*[^#]'
grep -E '^[ \t]*[^#]'
Upvotes: 1
Views: 97
Reputation: 113834
Try:
$ grep -E '^\s*[^#[:space:]]' hashfile
abcd
xx
Since a space is not #
, the regex ^\s*[^#]
will any line that begins with zero or more spaces followed by one space.
We could have used a blank and tab explicitly if we wanted:
$ grep -E '^\s*[^# \t]' hashfile
abcd
xx
\s
is a GNU extension to grep
. In extended regular expressions (-E
), [:space:]
is the character class containing white space characters. For a portable solution, use:
$ grep -E '^[[:space:]]*[^#[:space:]]' hashfile
abcd
xx
Upvotes: 1