GFL
GFL

Reputation: 1424

Find and replace using find and sed

This post shared how to remove html comments from a file at the command line.

sed -e :a -re 's/<!--.*?-->//g;/<!--/N;//ba' file.html

I'm trying to extend that to remove html comments from all files in a directory, but I'm having a hard time. Some of my attempts include:

 find /my/folder/plus/subfolders -name "*.html" -exec "sed -e :a -re 's/<!--.*?-->//g;/<!--/N;//ba'"

And based on this, I've tried this approach too:

find /my/folder/plus/subfolders -name "*.html" -exec sed -i s/<!--.*?-->//g;/<!--/N;//ba {} +

Where am I going wrong?

Upvotes: 0

Views: 160

Answers (1)

Dabombber
Dabombber

Reputation: 466

You just needed to add the in place option -i and change the file to {}.

find /my/folder/plus/subfolders -name "*.html" -exec sed -i -e :a -re 's/<!--.*?-->//g;/<!--/N;//ba' {} +

Upvotes: 1

Related Questions