-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 !
In grep
, -F
will cause patterns to match literally ie no Regex interpretation is done on the pattern(s).
Multiple patterns can be inputted by \\n
ie 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
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
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.