Find and replace whole lines in many files

If you have a load of files which contain a line you don't want, you can use a combination of find and sed to remove them. This came in useful when one of my servers had been compromised and a number of html files had had malicious content inserted.

In this example, the find command finds all html files and sed is used to remove any lines consisting of the_content_to_remove. All files are backed up with a .bak extension.

Note: ALL found files are replaced, whether or not their content was modified.

find . -name "*.html" -exec sed -e '/^the_content_to_remove*/d' -i.bak {} \;
Last modified: 10/04/08 13:37:26
Go to top

Related Pages

No related pages or links.

Login/out

Login

Forgot Password?
Go to top
Go to top