I have a task where it says:
grep -n -e "^[[:space:]]" \
-e '#[[:space:]]' $ARG | grep -e include
(after the " \ " the code part is on the bottom line)
What does "#"
mean in the grep line
I have a task where it says:
grep -n -e "^[[:space:]]" \
-e '#[[:space:]]' $ARG | grep -e include
(after the " \ " the code part is on the bottom line)
What does "#"
mean in the grep line
#
has no special meaning in regular expressions, it's just matching the character literally. So the first grep
matches lines that begin with whitespace or have whitespace after a #
character.
They could have used an extended regular expression and matched them both in a single regexp.
grep -E -n '(^|#)[[:space:]]' "$ARG" | grep include
The #
is trivial; like most other characters in regular expressions, it simply matches itself.
The double -e
is actually more interesting here; you can supply more than one search expression by passing the -e
option multiple times. (A single -e
is rarely useful, though it's necessary if you want to pass in a regular expression which would otherwise look like an option to grep
, like -n
or, of course, -e
.)