仅使用 grep 显示完全匹配 [英] Display exact matches only with grep

查看:40
本文介绍了仅使用 grep 显示完全匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅显示所有结束正常的作业?

How can I display all jobs that ended OK only?

当我尝试下面的命令时,它同时显示 OK 和 NOTOK,因为两者都有OK"

When I try the command below, it shows both OK and NOTOK since both have "OK"

ctmpsm -listall application | grep OK

推荐答案

您需要更具体的表达方式.尝试 grep " OK$"grep "[0-9]* OK".您想选择与您想要的匹配的模式,但不会匹配您不想要的.该模式将取决于您的整个文件内容可能是什么样子.

You need a more specific expression. Try grep " OK$" or grep "[0-9]* OK". You want to choose a pattern that matches what you want, but won't match what you don't want. That pattern will depend upon what your whole file contents might look like.

您也可以这样做:grep -w "OK" 它将只匹配整个单词OK",例如1 OK"但不会匹配1OK"或OKFINE".

You can also do: grep -w "OK" which will only match a whole word "OK", such as "1 OK" but won't match "1OK" or "OKFINE".

$ cat test.txt | grep -w "OK"
1 OK
2 OK
4 OK

这篇关于仅使用 grep 显示完全匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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