I know that there's
$ but those are for the beginning and end of line, I am trying to match the beginning and end of string/word.
I tried to use
\b, which didn't work. For example:
echo "lol llol" | grep -E \blol
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You can use either of these, depending on what you're trying to display:
$ echo "lol llol" | grep -E "\blol" lol llol $ echo "lol llol" | grep -Eo "\blol" lol
Putting the regex in quotes solves your matching problem. The
-o flag causes grep to only print the matched string instead of the entire line.