Question

In the man page for grep it says that:

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

What is meant here by word?

I know that word is defined in -w, but here is the proof that it has a different meaning in this context:

If file 'test' contains hi/, and I grep -w 'hi/' test, I get a match, but if I grep 'hi/\>' test, I don't.

Was it helpful?

Solution

The beginning of a word is a word character (a letter, number, or underscore) that is not preceded by another word character, and the end of a word is a word character that is not followed by another word character. A "word" is then just a series of word characters.

The reason hi/\> doesn't match hi/ is because the \> is preceded by a non-word character (/), and so that can't be the location of an end-of-word.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top