如何在 Linux 中 grep '---'?grep:无法识别的选项“---" [英] How to grep '---' in Linux? grep: unrecognized option '---'
问题描述
我有一个新安装的网络应用程序.其中有一个下拉菜单,其中一个选项是 ---
.我想要做的是将其更改为 All
.所以我导航到应用程序文件夹并尝试了以下命令.
I have a newly installed web application. In that there is a drop down where one option is ---
. What I want to do is change that to All
. So I navigated to application folder and tried the below command.
grep -ir '---' .
我最终得到以下错误.
grep: unrecognized option '---'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
鉴于我正在使用
Distributor ID: Ubuntu
Description: Ubuntu 10.04.4 LTS
Release: 10.04
Codename: lucid
如何在 Linux 中 grep '---' ?
How to grep '---' in Linux ?
推荐答案
发生这种情况是因为 grep
将 ---
解释为一个选项而不是要查找的文本.相反,使用 --
:
This happens because grep
interprets ---
as an option instead of a text to look for. Instead, use --
:
grep -- "---" your_file
通过这种方式,您可以告诉 grep
其余的不是命令行选项.
This way, you tell grep
that the rest is not a command line option.
其他选项:
使用
grep -e
(参见我添加的 Kent 的解决方案)当他已经发布了 - 直到现在才注意到):
use
grep -e
(see Kent's solution, as I added it when he had already posted it - didn't notice it until now):
使用 awk
(参见 anubhava 的解决方案)或 sed代码>:
use awk
(see anubhava's solution) or sed
:
sed -n '/---/p' file
-n
阻止 sed
打印行(其默认操作).然后 /---
匹配那些包含 ---
的行,并且 /p
使它们被打印出来.
-n
prevents sed
from printing the lines (its default action). Then /---
matches those lines containing ---
and /p
makes them be printed.
这篇关于如何在 Linux 中 grep '---'?grep:无法识别的选项“---"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!