Reputation: 1998
-F
is an option of grep
, from the manual below:
interpret pattern as a list of fixed strings,separated by newlines,any of which is to be matched
My question is
\n
or \
?grep -F a\nh file
is not valid if I want to find lines which starts with a character a
or h
.Thanks in advance !
Upvotes: 3
Views: 3608
Reputation: 42097
In grep
, -F
will cause patterns to match literally i.e. no Regex interpretation is done on the pattern(s).
Multiple patterns can be inputted by \n
i.e. newline separation.
Not all shells convert \n
to newline by default, you can use $'a\nh'
in that case.
Example:
$ echo $'foo\nf.o\nba.r\nbaar\n'
foo
f.o
ba.r
baar
$ grep -F $'f.o\nba.r' <<<$'foo\nf.o\nba.r\nbaar\n'
f.o
ba.r
Upvotes: 5
Reputation: 47119
By default the pattern is a Basic Regular Expressions (BRE) pattern, but with -F
it will be interpreted as a literal string with no metacharacters.
You can also use -E
which will enable Extended Regular Expressions (ERE).
% grep -F '..' <<< $'hello\nworld\n...'
...
% grep '..' <<< $'hello\nworld\n...'
hello
world
...
Upvotes: 1