Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Grep match only the exact string in the line

I’m trying to grep for the word OK from the output of the below command

valtool --validate <filename> which throws below outputs

If success –> <filename>: layers signatures val OK & If failure–> <filename>: layers signatures val NOT OK

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

log='/home/files/rapid.so: layers signatures NOT OK'
~$ echo $log
/home/files/rapid.so: layers signatures NOT OK

~$ echo $log |grep -w 'OK' ;echo $?
/home/files/rapid.so: layers signatures NOT OK
0

Ideally, it should return 1 as per the requirement. I tried other options suggested on this forum but nothing helped.
I’m looking to get a return value of 0 if only OK is matched, else 1.

bash --version
GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)

>Solution :

So invert NOT OK.

! grep "NOT OK$" <<<"$log"; echo $?
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading