如果整行匹配,如何使grep仅匹配? [英] How to make grep only match if the entire line matches?
本文介绍了如果整行匹配,如何使grep仅匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些:
$ cat a.tmp
ABB.log
ABB.log.122
ABB.log.123
我想找到完全匹配的 ABB.log.
I wanted to find a exact match of ABB.log.
但是当我这样做时
$ grep -w ABB.log a.tmp
ABB.log
ABB.log.122
ABB.log.123
它显示了所有这些.
我可以使用 grep 获得我想要的东西吗?
Can I get what I wanted using grep?
推荐答案
只需指定正则表达式锚点.
Simply specify the regexp anchors.
grep '^ABB.log$' a.tmp
这篇关于如果整行匹配,如何使grep仅匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文