Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm running a Web Server in a Virtual Box for testing some projects. And I noticed that some of the html files have this unwanted lines. I want these lines of code from multiple html/htm files removed so I did it like this:

find /Desktop/TEST_REMOVAL3/ -name '*.html' -or -name '*.htm' -or -name '*.php' | sed -i "/<SCRIPT Language=VBScript>/,/ //--></SCRIPT><!-- /d"

So far, the 1st part where if looks/finds all html files works. The part where I need to remove the lines starting from <SCRIPT Language=VBS> to </SCRIPT> using sed fails :D

I'll try to figure it out again while waiting for your suggestions and scolding on where I went wrong :D

share|improve this question
3  
Close voters: This question is not off-topic! Questions about shell scripting and bash are perfectly fine here as long as the OP is running Ubuntu. –  Seth Apr 23 at 0:22

1 Answer 1

up vote 4 down vote accepted

If you want to use the file list from find as arguments for the sed command (instead as imput, which is what your line is doing), you have to use either the xargs command:

find dir -name '*.html' | xargs -d \\n sed -i "COMMANDS"

In which case xargs takes the file list, using newline (\n) as separator between file names and starts sed with them as arguments.

Or you use the -exec option of find:

find dir -name '*.html' -exec sed -i "COMMANDS" {} +

In which case find will run the command between -exec and + while replacing {} with (a list of) file names. There is also

find dir -name '*.html' -exec sed -i "COMMANDS" {} \;

which does essentially the same, but starts a new sed for every single file name.

share|improve this answer
    
Also, simplify your sed statements and use single quotes , sed -i '/VBScript/,/SCRIPT>/d' , you do not need to match the entire line –  bodhi.zazen Apr 22 at 19:14

Your Answer

 
discard

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.