To search exact pattern

Hi,

I need to search the exact pattern in a file

file.txt

AUS.txt|AUS.chk
NZ.txt|NZ.ch

I am getting the result as
AUS.txt|AUS.chk with below code but i need only AUS.txt to be printed

 
 
grep AUS.txt file.txt
 

Not clear what exact you want.

Please give some more details about what you want.

$ awk '/AUS\.txt/{print "AUS.txt"}' file

AUS.txt

Hi,

Actually what i need is to grep alone AUS.txt which should be resulted in output instead of AUS.txt|AUS.chk I am using grep to check and required to return in grep itself

grep AUS.txt file.txt

i am getting AUS.txt|AUS.chk but i need AUS.txt using grep

rohit ,

run below command :

grep 'AUS.txt' filename 

Hi,

I have tried it its retruning AUS.txt|AUS.chk i want to return only AUS.txt using grep

try

grep -o AUS.txt file.txt

Hi i am not able to work with grep -o in my OS

Try:

tr '|' '\n' < file | grep "AUS.txt"

Well the default behaviour is to return the line with the searched for string, if you don't have the -o flag available you could discard the line and echo the matched text or discard with sed, or write a filter with awk

grep AUS.txt file.txt > /dev/null && echo AUS.txt
grep AUS.txt file.txt | sed 's/^.+(AUS.txt).+$/\1/'