如果整行匹配,如何使grep唯一匹配? [英] How to make grep only match if the entire line matches?

查看:666
本文介绍了如果整行匹配,如何使grep唯一匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些:

  $ cat a.tmp 
ABB.log
ABB.log .122
ABB.log.123

我想找到ABB的完全匹配。登录。



但是,当我做了

$ $ p $ $ $ $ $ $ grep -w ABB.log a.tmp
ABB.log
ABB.log.122
ABB.log.123

它显示了所有这些。



我能用grep得到我想要的吗?



  grep'^ AAA\.log $ h2_lin>解决方案

只需指定锚点。 'a.tmp


I have these:

$ cat a.tmp
ABB.log
ABB.log.122
ABB.log.123

I wanted to find a exact match of ABB.log.

But when I did

$ grep -w ABB.log a.tmp
ABB.log
ABB.log.122
ABB.log.123

it shows all of them.

Can I get what I wanted using grep?

解决方案

Simply specify the anchors.

grep '^AAA\.log$' a.tmp

这篇关于如果整行匹配,如何使grep唯一匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆