[英]What is the meaning of the -F option in grep manual
-F
is an option of grep
, from the manual below: -F
是grep
一个选项,来自以下手册:
interpret pattern as a list of fixed strings,separated by newlines,any of which is to be matched
将模式解释为固定字符串列表,由换行符分隔,其中任何一个都应匹配
My question is 我的问题是
\\n
or \\
? \\n
或\\
什么? grep -F a\\nh file
is not valid if I want to find lines which starts with a character a
or h
. a
或h
开头的行,似乎grep -F a\\nh file
无效。 Thanks in advance ! 提前致谢 !
In grep
, -F
will cause patterns to match literally ie no Regex interpretation is done on the pattern(s). 在
grep
, -F
将导致模式从字面上进行匹配,即,不对模式进行正则表达式解释。
Multiple patterns can be inputted by \\n
ie newline separation. \\n
可以输入多个模式,即换行符。
Not all shells convert \\n
to newline by default, you can use $'a\\nh'
in that case. 并非所有的shell默认都将
\\n
转换为换行符,在这种情况下,您可以使用$'a\\nh'
。
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. 默认情况下,该模式是基本正则表达式(BRE)模式,但使用
-F
它将被解释为不带任何元字符的文字字符串。
You can also use -E
which will enable Extended Regular Expressions (ERE). 您也可以使用
-E
来启用扩展正则表达式(ERE)。
% grep -F '..' <<< $'hello\nworld\n...'
...
% grep '..' <<< $'hello\nworld\n...'
hello
world
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.