0

What is the difference between: grep '\<hi\>' coco.txt, and grep 'hi' coco.txt? I applied these commands in terminal, but I do not see any difference.

3

In grep, \< stands for beginning of word and \> stands for end of word.

From man grep:

The Backslash Character and Special Expressions
   The symbols \< and \>  respectively  match  the  empty  string  at  the
   beginning and end of a word.  The symbol \b matches the empty string at
   the edge of a word, and \B matches the empty string provided  it's  not
   at the edge of a word.  The symbol \w is a synonym for [_[:alnum:]] and
   \W is a synonym for [^_[:alnum:]].

So, grep '\<hi\>' will match any line containing the word hi and grep 'hi' will match any line containing the sequence of characters hi:

$ grep '\<hi\>' <<< "hi"
hi
$ grep '\<hi\>' <<< "chimes"
$ # no output since no match
$ grep '\<hi\>' <<< "hi-fi"
hi-fi
$ grep '\<hi\>' <<< "high voltage"
$ # no output since no match
  • @gniourf_gniourf you are answer seems better , thank you man , – sosoma Nov 3 '13 at 11:46
  • @RaduRădeanu Radeanu , thank you, for youre help .^_^ – sosoma Nov 3 '13 at 11:47

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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