使用UNIX清理精确的单词 [英] Grepping for exact words with UNIX

查看:92
本文介绍了使用UNIX清理精确的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



示例:Log.txt文件包含以下文本:

  aaa 
bbb
cccaaa --->这应该不算在grep输出中

我使用下面的代码 - $ / b
$ b

  count = $? 
count = $(grep -c aaa $ EAT_Setup_BJ3 / Log.txt)

这里输出应该是==> 1不是2,使用上面的代码即时获取2作为输出
有些东西是缺失的所以,任何人可以帮助我这个请吗?

解决方案

Word边界匹配是对标准POSIX grep实用程序的扩展。它可能可用或不可用。如果你想搜索的话可移植,我建议你看看perl,而不是,你会用在哪里

  perl -ne'print如果/ \baaa\b /'$ EAT_Setup_BJ3 / Log.txt 


I want to search Exact word pattern in Unix,

Example : Log.txt file contains following text :

aaa
bbb
cccaaa   ---> this should not be counted in grep output

I am using following code-

count=$?
count=$(grep -c aaa $EAT_Setup_BJ3/Log.txt)

Here output should be ==> 1 not 2, using above code i m getting 2 as output something is missing So, can any one help me for the this please?

解决方案

Word boundary matching is an extension to the standard POSIX grep utility. It might be available or not. If you want to search for words portably, I suggest you look into perl instead, where you would use

perl -ne 'print if /\baaa\b/' $EAT_Setup_BJ3/Log.txt

这篇关于使用UNIX清理精确的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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