如何解决为什么当我使用-w时grep会返回一个匹配项,而没有它,为什么呢?
我运行了以下命令:
then
假设在fileB中有一个像这样的字符串:astringlikethis12345
因为我想查看fileB中的内容,而不是fileA中的内容,但是它没有返回任何匹配。 但是如果我用-w执行相同的命令:
when {
$t isa person;
$car isa car;
$t2 isa person;
$r ($t,$car) isa ownership;
$r2 ($t2,$car) isa ownership;
},then {
$car has age 23;
};
when {
$t isa person;
$car isa car;
$t2 isa person;
$r ($t,then {
($car,$t2) isa ownership;
};
它返回我一直在寻找的字符串,这是为什么? -w可以匹配整个字符串,但是即使没有,它也应该返回匹配值,对吗?无论是部分还是全部。
谢谢
解决方法
在fileA中检查要在搜索fileA中要排除的单词。该单词旁边可能会有空格或制表符。
它在我的系统上按预期运行
来自grep帮助:
-w,--word-regexp强制PATTERN只匹配整个单词
-v,--invert-match选择不匹配的行
[root @ project1-master〜]#cat filea
这个
[root @ project1-master〜]#cat fileawithspacenexttothis
这个
[root @ project1-master〜]#cat fileb
这个
那个
这些
thisthis
这是那个
- “ grep -f filea -v fileb”等效于“ grep -v this fileb”,因此它会返回&这些
[root @ project1-master〜]#grep -f文件a -v文件b 那
这些
2。“ grep -f filea -v -w fileb”等同于grep -v -w this fileb,因此它将显示'thisthis',并且在'thisthis'中有单词边界
[root @ project1-master〜]#grep -f filea -v -w fileb
那个
这些
thisthis
- grep -f fileawithspacenexttothis -v fileb等效于“ grep -v'this'fileb”
[root @ project1-master〜]#grep -f fileawithspacenexttothis -v fileb
那个
这些
thisthis
4.grep -f fileawithspacenexttothis -v -w fileb等效于“ grep -v -w'this'fileb”,由于其中没有单词边界,因此将显示“ thisthis”和“ this this that” “这个”
[root @ project1-master〜]#grep -f fileawithspacenexttothis -v -w fileb
那个
这些
thisthis
这是那个
如果提供filea和fileb的示例内容以及grep输出,可能会很有用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。