如何grep特殊字符串,例如'-E *'? [重复]

问题描述 投票:0回答:1

grep.txt包含简单的行。

echo -n 'test the special characters
-E
-E*
-f
-F' > grep.txt

-F in grep:将PATTERN解释为固定字符串列表(而不是常规字符串)表达式),以换行符分隔,其中任何一个都应匹配。

使用-Fn获取匹配的行号:

grep -Fn  'E*'  grep.txt
3:-E*
grep -Fn  'E'   grep.txt
2:-E
3:-E*

我获得了理想的结果,现在想匹配特殊字符串,例如-E*

grep -Fn  '-E*'  grep.txt
grep: conflicting matchers specified

[使用grep搜索-E*时如何获得预期的结果?

3:-E*     

-F参数对E*有影响,如何使其对-E*有影响?

regex grep
1个回答
-1
投票
您可以明确指定-e参数:

grep -ne '-E*' grep.txt

© www.soinside.com 2019 - 2024. All rights reserved.