Show exact matches only with GREP

How can I display all tasks that ended only with OK?

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

ctmpsm -listall application | grep OK 
+10
source share
7 answers

You need a more specific expression. Try grep " OK$" or grep "[0-9]* OK" . You want to select a template that matches what you want, but doesn't match what you don’t want. This template will depend on how your content will look like all the content.

You can also do: grep -w "OK" , which will only match the whole word "OK", for example, "1 OK", but will not match "1OK" or "OKFINE".

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

This may work for you.

 grep -E '(^|\s)OK($|\s)' 
+9
source

Try the following:

 Alex Misuno@hp4530s ~ $ cat test.txt 1 OK 2 OK 3 NOTOK 4 OK 5 NOTOK Alex Misuno@hp4530s ~ $ cat test.txt | grep ".* OK$" 1 OK 2 OK 4 OK 
+1
source

This worked for me :

 grep "\bsearch_word\b" text_file > output.txt ## \b indicates boundaries. This is much faster. 

or,

 grep -w "search_word" text_file > output.txt 
0
source

try the following: grep -P '^ (tomcat !?)' tst1.txt

It will search for a specific word in the txt file. Here we are trying to find the word 'tomcat'

0
source

^ marks the beginning of a line, and $ marks the end of a line. This will only return exact "OK" matches.

(This also works with double quotes, if that is your preference.)

 grep '^OK$' 
0
source

Try the command below because it works fine:

 grep -ow "yourstring" crosscheck:- 

Delete the instance of the word from the file, then re-run this command and it should display an empty result.

-2
source

Source: https://habr.com/ru/post/956678/


All Articles