Display exact matches only with grep

前端 未结 8 961
半阙折子戏
半阙折子戏 2020-12-09 16:26

How can I display all jobs that ended OK only?

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

ctmpsm -listall applic         


        
8条回答
  •  旧时难觅i
    2020-12-09 16:40

    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.

    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
    

提交回复
热议问题