使用 UNIX 查找确切的单词 [英] Grepping for exact words with UNIX

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

问题描述

我想在 Unix 中搜索精确的单词模式.示例: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 looking for aaa

我正在使用以下代码:

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

这里的输出应该是 ==> 1 而不是 2,使用上面的代码我得到 2 作为输出.有什么东西不见了,有人可以帮我吗?

Here output should be ==> 1 not 2, using above code I am getting 2 as output. Something is missing, so can any one help me for the this please?

推荐答案

词边界匹配是标准 POSIX grep 实用程序的扩展.它可能可用或不可用.如果你想便携地搜索单词,我建议你查看 perl,你会在那里使用

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 /aaa/' $EAT_Setup_BJ3/Log.txt

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

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