Grep to find an exact string

Hi all,

I tried searching the forum for this, and I read numerous suggestions here and even on other forums, and I cannot get this to want the way that I need it to. I tried grep -W / -f to no luck. Here is what I have. I have a list of file names-

  
 FILE1-FILE1TEST,FILE1RELATION
 FILE1-FILE1TESTBACKUP,FILE1TESTT
 1234-FILE1TEST,FILE1234
  
 

I want to return only lines that contain FILE1-FILE1TEST exactly, not the other two hits, which for this test, I guess they can be considered, old data, or "versioned" data. here is what I have tried:

grep -F 'FILE1-FILE1TEST' output.out
grep "\FILE1-FILE1TEST\b" output.out
grep '^[^#]*FILE1-FILE1TEST' output.out
grep -w "FILE1-FILE1TEST" output.out
grep "\<FILE1-FILE1TEST\>" output.out  
 

Any hints? I have a feeling grep is the right way to approach this but I could be incorrect. thanks

grep "^FILE1-FILE1TEST," filename

Another way to approach this would be awk, which understands the concepts of seperators and fields, so you can say "Print when field one matches this exact text", which seems to me a nicer way to write it but YMMV. Both work.

awk -F, '$1 == V' V="FILE1-FILE1TEST" inputfile

What exactly do you dislike with grep s 2, 4, and 5? They all yield FILE1-FILE1TEST,FILE1RELATION

IMO you need to supply a suitable anchor for the pattern you are looking for in order to filter out lines that are similar but don't match your criteria...

grep '^FILE1-FILE1TEST[^a-zA-Z]' output.out

What is your OS and version?

This is being done on AIX 7.1

Do you only want to find the string you're searching for at the start of a line? Or do you want to display a line if the string you're searching for appears at the end of a line?

Do all lines have two fields (as in your example)? Or, could some lines have only one field. Could some lines three or more fields?

grep on AIX does not have word boundary operator extensions (GNU,BSD) like \< , \> or \b , so they will not work.
It does however have the -w extension so I do not understand why

grep -w "FILE1-FILE1TEST" output.out

would not work.

Anyway, you could try this, which should work with any (POSIX compliant) grep:

grep -E '(^|[^[:alnum:]_])FILE1-FILE1TEST([^[:alnum:]_]|$)' output.out

--
Note that the data sample has a leading space on every line..