0

I wanted to search for this particular string $string['site:config'] in my folder. But when I use a normal grep function grep -r "$string['site:config']" it gives me random results.

6
  • @ylabidi: So, in this case I cannot search for this particular string? Commented Apr 1, 2013 at 4:41
  • use -F to force grep to interpret the given pattern as a normal string and not as a regex. Commented Apr 1, 2013 at 4:42
  • The problem with your pattern is that characters like $ [ ] are characters used to define regular expressions and you have either to escape them or instruct grep to look for the given string as is, without attempting to interpret it as a regular expression. Commented Apr 1, 2013 at 4:44
  • Switch over to TextCrawler instead \o/ Commented Apr 1, 2013 at 4:45
  • 1
    How's that working for you ? Commented Apr 1, 2013 at 4:48

1 Answer 1

1

The problem with your pattern is that characters like $ [ ] are characters used to define regular expressions and you have either to escape them:

grep "\$string\['site:config'\]"

or instruct grep to look for the given string as is:

grep -F "$string['site:config']"

without attempting to interpret it as a regular expression.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.