Grep Exact word

This may be stupid question but not able to solve it.

How to grep exact word and line along with it.

TEST:/u00/app/oracle/product/10.2.0/TEST:N
TEST2:/u00/app/oracle/product/10.2.0/ODS:N
TEST3:/u00/app/oracle/product/10.2.0/TEST:N
TEST4:/u00/app/oracle/product/10.2.0/ODS:N
TEST5:/u00/app/oracle/product/10.2.0/TEST:N
TEST6:/u00/app/oracle/product/10.2.0/ODS:N

if i do grep TEST /etc/oratab
it gives me all lines
How to grep lines only with TEST2.

is there any specific argument in grep.

you can google it also.

grep -w 
1 Like

If you are interested in awk, then you can try the below.

 
$ awk -F: '$1=="TEST2"' input.txt
TEST2:/u00/app/oracle/product/10.2.0/ODS:N
 
$ awk -F: '$1=="TEST2" { print }' input.txt
TEST2:/u00/app/oracle/product/10.2.0/ODS:N

grep -F 'pattern'  filename

turns off regular expressions and does an exact text match instead.

This is no wonder: when you search for "TEST", you will find everything containing "TEST", therefore "TEST2", "XTEST", "TESTX", etc.

If you want to find only specific lines you will have to enlarge your search pattern so much that it becomes distinct. In your case this could be done by including the ":", which seems to separate the first from the second part of the line. Searching for "TEST:" will only find the first line, not the others.

I hope this helps.

bakunin