Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list of files where I need to remove some lines that have been added yesterday by a spambot. The section I want to remove looks like this:

<script>[...] bunch of malware code [...]</script>

That section seems to have been appended to the files, so I can be relatively sure it's the last lines of each file that contain this part.

Now I know a bit of Linux, but not enough to do this via a command. How would I go about and do this?

share|improve this question
up vote 4 down vote accepted

Is the malware code consistent? does it start and end with the same text in all cases??

If you can write a regexp, you can do something like:

perl -npi.bak -e 's/startofcode.*?endofcode//' file1 file2 file3 orglob*
share|improve this answer
or sed if perl is not available on the machine (unusual but could happen) – Ophidian May 14 '10 at 15:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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