scripting - Remove specific lines inside a range with sed -
i'm trying remove block inside pair of matching patterns using sed. given block like:
<span class="fxlbc-t1-x-x-172">m<span class="small-caps">a</span><span class="small-caps">r</span><span class="small-caps">s</span></span> <span class="fxlbc-t1-x-x-248">r<span class="small-caps">a</span><span class="small-caps">i</span><span class="small-caps">s</span><span class="small-caps">o</span><span class="small-caps">n</span></span>
i need remove block:
<span class="fxlbc-t1-x-x-172">m<span class="small-caps">a</span><span class="small-caps">r</span><span class="small-caps">s</span></span>
i'm trying in sed. first problem i'm hitting when using n
selector, problem of odd vs lines. i've fixed doing this:
sed -i 'n /.*<span \nclass="fxlbc-t1-x-x-172".*/,/.*class="fxlbc-t1-x-x-248".*/ { /.*fxlbc-t1-x-x-172.*/d }' test.html # add empty line sed -i '1i\ ' test.html sed -i 'n /.*<span \nclass="fxlbc-t1-x-x-172".*/,/.*class="fxlbc-t1-x-x-248".*/ { /.*fxlbc-t1-x-x-172.*/d, /.* }' test.html
i'm pretty sure there must easier way of doing it, , i'm stuck how remove other lines of block (without removing fxlbc-t1-x-x-248
span
line). idea?
i given answer problem colleague:
sed -i ':a ; $! { n ; ba } ; $s/\(<span\( \|\n\|\t\)\+class="fxlbc-t1-x-x-172">[^4]\+\)\(<span\( \|\n\|\t\)\+class="fxlbc-t1-x-x-248">\)/\3/g' test.html
it puts whole file in buffer, , standard search , replace on buffered string. reckon it's ugly though, trick.
Comments
Post a Comment