0

I want to search

$GLOBALS["\x61\156\x75\156\x61"] using grep but " and / not working perfectly.

grep -rl "$GLOBALS["\x61\156\x75\156\x61"]" <filename>

$GLOBALS["\x61\156\x75\156\x61"] is a virus malware starting code, lots of files are affected. I have a script through I want search effected files and remove top line

1
  • Are you in a recent version of bash that supports associative arrays, and GLOBALS refers to an associative array? Or are you trying to search for literal text equal to $GLOBALS["\x61\156\x75\156\x61"]? Commented Feb 17, 2015 at 13:10

1 Answer 1

2

Since you are looking for an exact match and you don't want the expression to be interpreted by grep, you have to use -F and single quotes to avoid the variable being expanded:

grep -Frl '$GLOBALS["\x61\156\x75\156\x61"]' <filename>
      ^   ^                                ^

From man grep:

-F, --fixed-strings

Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by POSIX.)


See another example of the usage of -F together with single quotes:

We create a file like this:

$ cat a
hello
${myarray[0]}
bye

And an array:

$ myarray=('hello' 'how' 'are' 'you')

Let's use single quotes and look for the value:

$ grep '${myarray[0]}' a
$ 

Let's use fixed string with double quotes -> it gets interpreted!

$ grep -F "${myarray[0]}" a
hello

Let's use -F and single quotes:

$ grep -F '${myarray[0]}' a
${myarray[0]}                    #this works!
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.