Re: sed on html pages
Ron Scott-Adams <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
There’s a larger problem here: do not use RegEx to parse HTML. It ends in sadness, guaranteed. See http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 It’s tempting to assume that with a little RegEx you can whip HTML pages into the shape you want, but it is a steadily degrading process, and it is simply the wrong way to do things, for various reasons outlined in the above link and elsewhere. There’s a reason why dynamic web languages were invented. At some point, the best way to provide help with sed is to assist in the understanding of when it is the wrong tool for the job. This is such a point. On Mar 1, 2014, at 5:30 PM, Silvio Siefke <[email protected]> wrote: > On Sat, 01 Mar 2014 16:52:11 -0500 Joel Hammer <[email protected]> > wrote: > > > Not sure I understand all you want to do, but, to insert a line break, > > this works: > > > > sed s/target/\n &/ > > ok that work not so i like, it break </title> but i has now try with > <!-- and it works. Hhh funny i swear i search all day break line sed > and all what i found not work. hhhh maybe i to stupid for google :) > > One question i have then im happy. When i delete a html tag, how can > i fill the whitespace? > > Example (tidy clean append id="ext"> > <a href="whatever" title="whatever" name="ext" id="ext">whatever</a> > > i use sed: > find -type f -name '*html' -exec sed -i 's!id="ext"!!g' {} \; > > this come out: > <a href="whatever" title="whatever" name="ext" >whatever</a> > > But can sed clean all so that is not whitespace in it? > > better come out: > <a href="whatever" title="whatever" name="ext">whatever</a> > > And last question im happy for first use of sed :) > > Can i combined the follow 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 > > Thank you for help & Nice Day > Silvio > > >