-2

I have a file test.txt which contains this text data

# cat test.txt
*@=>*@

if I use grep to check if the string is in the file using this way

# grep "*@=>*@" test.txt
#

it returns nothing..

while if I grep a partial string search

# grep "*@=>" test.txt
# *@=>*@

it works correctly ..

Why in the first case do grep return nothing ?

gr68
  • 420
  • 1
  • 10
  • 25
  • 1
    Use `-F`: `grep -F '*@=>*@' test.txt` – anubhava Apr 08 '21 at 16:37
  • 1
    It is written in the manual (type `man grep` on your terminal): _"The grep utility searches any given input files, selecting lines that match one or more patterns. By default, a pattern matches an input line if the regular expression (RE) in the pattern matches the input line without its trailing newline."_ – axiac Apr 08 '21 at 16:48

1 Answers1

0

The asterisk is special to grep, it means "the previous token is repeated zero or more times". So >* would match an empty string or > or >> etc.

To match an asterisk, backslash it in the pattern:

grep '\*@=>\*@' test.txt

(The first asterisk follows no token, so the backslash is optional.)

choroba
  • 231,213
  • 25
  • 204
  • 289