Re: sed on html pages
Sven Guckes <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
* Silvio Siefke <[email protected]> [2014-03-02 02:52]: > Can i combine the following commands to one sed command: > > siefke blog $ cat ~/.bin/scripts/webclean > #!/bin/bash > find -type f -name '*html' -exec tidy -m -config ~/.config/tidy/com {} \; > find -type f -name '*html' -exec sed -i '/^$/d' {} \; > find -type f -name '*html' -exec sed -i 's|<[/]\?div[^>]*>||g' {} \; > find -type f -name '*html' -exec sed -i 's!id="ext"!!g' {} \; > find -type f -name '*html' -exec sed -i 's!id="vid"!!g' {} \; > find -type f -name '*html' -exec sed -i 's! !!g' {} \; > exit yes, you can put all commands into a file and tell sed to run them from there: sed -f file this would probably change your script to this: $ cat sedcommands s|<[/]\?div[^>]*>||g s!id="ext"!!g s!id="vid"!!g s! !!g $ cat silvioscript #!/bin/bash find -type f -name '*html' -exec tidy -m -config ~/.config/tidy/com {} \; find -type f -name '*html' -exec sed -i -f sedcommands {} \; but here you use the same find command twice to find all the html files yet again for the next command. you only need to find all html files only once, then execute the tidy+sed commands on these in one go. if your shell is zsh then finding the html files is as easy as using this pattern: **/*html so you can put the finding of files outside the script. and when you put tidy+sed into on script then it should all boil down to this: script **/*html okay, the filename globbing *might* fill up the space, depending on how many html files you actually got. in this case you are advised to use find+xargs. find ... | xargs script so much for ideas. :) Sven