Reputation: 53
I am learning bash and I have come across regular expressions.
There is an exercise where I have to match a word and I tried to use \b<word>\b
but for some reason it was not matched until I used \\b<word>\\b
. I actually tried it out of desperation when I couldn't understand why \b
wasn't working.
Upvotes: 5
Views: 2343
Reputation: 1035
You are proabably using grep \bword\b
which is really grep bwordb
after bash parses the backslashes.
Use grep '\bword\b'
(note the single-quotes).
Upvotes: 4
Reputation: 896
You can also use grep -w word
to match whole words only.
Upvotes: 0