0

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?

Jens
  • 69,818
  • 15
  • 125
  • 179
GFL
  • 1,278
  • 2
  • 15
  • 24
  • 1
    put the `sed` script in a file and call it from `find` or xargs. Good luck. – shellter Jul 21 '19 at 05:03
  • Possible duplicate of [Find and replace with sed in directory and sub directories](https://stackoverflow.com/questions/6758963/find-and-replace-with-sed-in-directory-and-sub-directories) – tripleee Jul 21 '19 at 11:55

1 Answers1

1

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' {} +
Dabombber
  • 436
  • 3
  • 8
  • Are all these parameters, like `-i`, `-e`, `{}`, and `+` under the `find` command or the `sed` command? Is everything to the right of sed now operating under sed? – GFL Jul 22 '19 at 11:36
  • The `-exec` option is ended with `+` (or `\;`). So the `sed` command is `sed -i -e :a -re 's///g;/ – Dabombber Jul 22 '19 at 12:18