Remi Avan-Nomayo
Remi Avan-Nomayo

Reputation: 53

using \b with grep pattern

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

Answers (2)

SIGSTACKFAULT
SIGSTACKFAULT

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

Krzysztof Kaszkowiak
Krzysztof Kaszkowiak

Reputation: 896

You can also use grep -w word to match whole words only.

Upvotes: 0

Related Questions