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.
3.3 The Backslash Character and Special Expressions The ' \ ' character, when followed by certain ordinary characters, takes a special meaning: ' \b ' Match the empty string at the edge of a word.
The grep command (short for Global Regular Expressions Print) is a powerful text processing tool for searching through files and directories. When grep is combined with regex (regular expressions), advanced searching and output filtering become simple.
The wildcard * (asterisk) can be a substitute for any number of letters, numbers, or characters. Note that the asterisk (*) works differently in grep. In grep the asterisk only matches multiples of the preceding character. The wildcard * can be a substitute for any number of letters, numbers, or characters.
The basic grep syntax when searching multiple patterns in a file includes using the grep command followed by strings and the name of the file or its path. The patterns need to be enclosed using single quotes and separated by the pipe symbol. Use the backslash before pipe | for regular expressions.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With