views:

663

answers:

3

I want a bash script to read all files recursively in a directory and remove some code (i.e a iframe virus) from it and save back the orignal file.

A: 

Would this be appropriate?

pavium
+2  A: 

You need to show that piece of iframe to remove, but generally you can do this with find & sed. If you don't know exactly how to write such script, give us more information like html files extensions and iframe pattern to remove (especialy if it is not always the same).

OK, suppose you have *.php files and you can remove every iframe tags (so, there is no other usefull iframes), you can use this solution: first, write change.sh shell script like this:

#!/bin/bash

sed 's/<iframe>.*<\/iframe>//g' < "$1" > "$1.tmp"
mv "$1.tmp" "$1"

Then, you can use this:

find . -name "*.php" | xargs -i ./change.sh {} \;

And that will do the job. My tests passed.

igustin