Home > Blockchain >  "grep -w" whole word option matches hyphenated words
"grep -w" whole word option matches hyphenated words

Time:02-24

Example command:

echo "am lorem-ipsum dolor" | grep -w -- lorem

This should return nothing, because "lorem" is not a whole word.

This word contains "-" character.

Any idea?

CodePudding user response:

For grep, word-constituent characters are letters, digits, and the underscore.

Therefore, hyphen is not a word-constituent and splits words.

  • Related