开发者

Get the matches only if the substring is not part of a string

开发者 https://www.devze.com 2023-03-16 15:58 出处:网络
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 t开发者_开发知识库he other string too are comi

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 t开发者_开发知识库he 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?


From the manual

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

So,

grep -nr '\<XML\>' .


Use the -w switch (exact word match).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消