matching a line with a literal asterisk "*" in grep


Question

Tried

$ echo "$STRING" | egrep "(\*)"

and also

$ echo "$STRING" | egrep '(\*)'

and countless other variations. I just want to match a line that contains a literal asterisk anywhere in the line.

1
21
10/23/2009 1:48:12 PM

Accepted Answer

Try a character class instead

echo "$STRING" | egrep '[*]' 
17
10/17/2009 3:18:00 AM

echo "$STRING" | fgrep '*'

fgrep is used to match the special characters.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon