【发布时间】:2018-02-04 11:34:48
【问题描述】:
我有一个文件,我想从该文件中 grep 一个特定的单词。我正在使用 MobaXterm。例如,我想 grep 单词 test-common 并且在我的文件中
1. Version: 1.0.0 test-common Author Created Path
2. Version: 1.0.0 test-common-config Author Created Path
3. Version: 1.0.0 unit-test-common Author Created Path
4. Version: 1.0.0 unit-test-common-config Author Created Path
我试过了:
-
grep test-common file -
grep "\\< test-common \\>" file(不返回任何东西) grep -w test-common filegrep -w "test-common " file-
grep -r "\btest-common\b" file(不返回任何内容) -
grep -sw test-common file(不工作) -
grep -o test-common file(不工作) -
grep \\< bil-common \\>文件
^bil-common 和 bil-common$ 也不起作用。
对于我有结果的命令,结果是:
test-common
test-common-config
这不是我想要的。任何帮助表示赞赏。
【问题讨论】:
-
结果如你所愿,不是吗?
-
不,我只想得到 test-common 而不是 test-common 和 test-common-config
-
如果该行没有其他字符,则可以进行整行匹配 -
grep -x 'test-common' file -
每一行还有其他信息。但为了不发布任何不必要的信息,我只写了我想找到的内容
-
@isovitis 用于文本处理,每个字符都可能变得重要...建议添加完整的示例输入行并显示预期输出.. 到目前为止,看到您的示例和 cmets,我无法理解您的用例
标签: linux bash shell unix grep