Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Please help me with writing a shell script that deletes line from virus JS files recursively.

String to remove: http://pastebin.com/ExjCK8GL

share|improve this question
"string to remove"? "virus"? "recursively"? – akira May 15 '12 at 16:34
What have you tried? your question in it's current form is pretty vague and likely unanswerable. how many js files are there? how many instances of this are there? – rlemon May 15 '12 at 16:39
JS files are infected. The virus is a string that I shared on pastebin. I tried to use the find ./ -type f -exec sed -i ‘s/string1/string2/’ {} \; but I do not know how to escape such a large line in the regular expression. Sorry for my bad English. – Ticksy May 15 '12 at 16:47
JS files several dozen. Half of them are infected. Just need to go through all the JS files and delete this line. But I do not know how to escape in order to use somewhere. – Ticksy May 15 '12 at 16:52

closed as not a real question by Sathya May 15 '12 at 17:57

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

As mentioned, your question is a little vague so my response might not be the answer you're looking for. I'll make what I feel are reasonable assumptions and give it a go anyway. My assumptions: you have that "pastebin.com" string in a number of files and these files are scattered around in many different directories but under one main directory.

Go to this main directory and run:

$ perl -i.bak -ne 'print if (!m<http://pastebin.com/ExjCK8GL>)' `find . -type f -exec fgrep -l http://pastebin.com/ExjCK8GL {} \;`

This command will strip out the line and create backup versions of each modified file with a ".bak" extension. Note: this command does not care if the line in question is something like:

Watch out for the virus at http://pastebin.com/ExjCK8GL, dude!

The command above will omit any line that matches "http://pastebin.com/ExjCK8GL", regardless of where that string occurred in the line, either by itself or amongst other less virus-y strings.

If you do want to match just the lines with that string and only that string, change the command to:

$ perl -i.bak -ne 'print if (!m<http://pastebin.com/ExjCK8GL>)' `find . -type f -exec grep -l '^http://pastebin.com/ExjCK8GL$' {} \;`
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.