grep for specific phrases
Is there a way to grep for an absolute string without returning partial word matches? Let's say I'm pulling a directory listing and looking for a particular file called test.txt. A ls shows:
Some.File test.txt test.txt.bak If I try to grep test.txt, I get test.txt and test.txt.bak. I just want to return test.txt. I tried using the -w command but it didn't work, I'm guessing because there's no special characters after .txt, like a space or tab, just a continuation of alphanumerics. Any way to do this? |
You can try grep -x.
|
That's exactly what I needed. Looks like I got my man lines crossed when I was looking at the flags. :D Thanks, colucix.
|
The way I read the manual, -x forces a match of the whole line.
How about grep "test.txt " or grep "test.txt[^.]" (These don't work if test.txt is at the end of the line) |
grep ^test.txt$ <yourfile>
|
"-w" ... :rolleyes:
|
All times are GMT -5. The time now is 07:14 AM. |