0

Hello I actually am looking for a string which is a substring of another string. So I am using grep to get the matches of this string, but the matches of the other string too are coming up.

grep -nr 'XML' .

when I do this, the matches for string "LIBXMLX" are also coming up. Is there a way to get matches only of XML and no LIBXMLX??

I am newbie to shell scripting, so how do I proceed with this?

0

3 Answers 3

3

From the manual

The symbols \< and \> respectively match the empty string at the beginning and end of a word.

So,

grep -nr '\<XML\>' .
0
0

Use the -w switch (exact word match).

1
  • <code>grep -wnr 'XML' .</code> I get all those results when I use this again!
    – macha
    Jul 1, 2011 at 19:40
0

It's kludgey, I know, but you could use ' XML' as the search string, thereby eliminating anything that doesn't have a space before the X. Just a thought. My interactions with grep are simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.