Search code examples
unixcontrol-m

Display exact matches only with grep


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 application | grep OK

Solution

  • 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