如何在Linux中grep'---'? grep:无法识别的选项'---' [英] How to grep '---' in Linux? grep: unrecognized option '---'
问题描述
我有一个新安装的网络应用程序。在那里有一个下拉选项,其中一个选项是 ---
。我想要做的是将其改为 All
。所以我导航到应用程序文件夹,并尝试下面的命令。
grep -ir'---'。
我最终得到了下面的错误。
grep:无法识别的选项'---'
用法:grep [OPTION] ... PATTERN [FILE] ...
尝试`grep --help'了解更多信息。
鉴于我在使用
分销商编号:Ubuntu
描述:Ubuntu 10.04.4 LTS
发行:10.04
代号:lucid
如何在Linux中使用grep'---'?
发生这种情况是因为 grep
将 -
:
grep - --- your_file
通过这种方式,您可以告诉 grep
其他的不是命令行选项。
其他选项: 使用 使用
grep -e
(请参阅肯特的解决方案,我添加了它,当他已经发布它 - 直到现在没有注意到它):
awk $ c $ (请参阅 anubhava的解决方案)或
sed
:
sed -n'/ --- / p'文件
-n
防止 sed
打印行(默认行为)。然后 / ---
与包含 ---
和 / p
使它们被打印。
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 '---' .
I end up with below error.
grep: unrecognized option '---'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
Given that I'm using
Distributor ID: Ubuntu
Description: Ubuntu 10.04.4 LTS
Release: 10.04
Codename: lucid
How to grep '---' in Linux ?
This happens because grep
interprets ---
as an option instead of a text to look for. Instead, use --
:
grep -- "---" your_file
This way, you tell grep
that the rest is not a command line option.
Other options:
use
grep -e
(see Kent's solution, as I added it when he had already posted it - didn't notice it until now):use
awk
(see anubhava's solution) orsed
:sed -n '/---/p' file
-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屋!