Linux – Grep words with special symbols

greplinuxspecial characters

How do I grep this? (Including the special characters)

"Limit reached."[\n]"

I tried back-slashing the special symbols but end up not working, like this:

grep '\"Limit reached\.\"\[\\n\]\" '

I also tried other techniques but also not working. Is there any other syntax you could suggest/advice?

Best Answer

use -F in grep

$ cat test.txt
"Limit reached."[\n]"
test
"Limit reached."[\n]"

$ grep -F '"Limit reached."[\n]"' test.txt
"Limit reached."[\n]"
"Limit reached."[\n]"

As per Manual page,

   -F, --fixed-strings, --fixed-regexp
          Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.  (-F is specified by> POSIX,
 --fixed-regexp is an obsoleted alias, please do not use it new scripts.)
Related Question