Say I've got some documents that contain several lines with KEYWORD
and some lines with PREFIX_KEYWORD
.
How would I match only these lines that have KEYWORD
and ignore the lines that have PREFIX_KEYWORD
on them?
Yes, I could grep for KEYWORD
, feed the results into the editor of my choice and let the editor delete all lines that have PREFIX_KEYWORD
but I'm asking whether there's a built-in way in grep to do this.
If this helps: I'm not interested in the exact match but only want to know whether there are occurrences of KEYWORD
in the file.
If you need the word
KEYWORD
by itself, why not regex forKEYWORD
with any special character before (space, newline, etc.)?One way would be to grep for your KEYWORD and filter out the rest. This could look like
Another way with a perl expression:
The same answer was given here: Regex to match specific strings without a given prefix
Try this:
man page for
-w
says: