sed case1

sed -i 's/class=notification-bar/class=notification-bar id=notification-bar/g' *.html
sed -i 's/class="sidebar site__sidebar"/class="sidebar site__sidebar" id=rmsidebar/g' *.html
sed -i 's/class=navigation__inner/class=navigation__inner id=navigation__inner/g' *.html
sed -i 's/class=navigation-sub>/class=navigation-sub id=navigation-sub>/g' *.html
sed -i 's/class=sponsors>/class=sponsors id=sponsors>/g' *.html
sed -i 's/class=page-links>/class=page-links id=page-links>/g' *.html
sed -i 's#<h1>Printable</h1>##g' *.html
sed -i 's/class=gitter__button/class=gitter__button id=gitter__button/g' *.html
sed -i 's/class=footer>/class=footer id=footer>/g' *.html
sed -i 's/class=contributors>/class=contributors id=contributors>/g' *.html
sed -i -e '/</footer>/{r sci.js' -e 'd}' *.html

找到匹配子段</footer>,注意有转义,替换为sci.js文件中的内容

sci.js

<script>
    //to remove sidebar, add "rmsidebar"
var tobeRm=["notification-bar", "navigation__inner", "navigation-sub", "sponsors", "page-links", "gitter__button", "footer", "contributors"];

for(let i=0;i<tobeRm.length;++i){
    let n = tobeRm[i];
    let e = document.getElementById(n)
    if(e && e.parentNode){
        e.parentNode.removeChild(e);
        console.log("dom:"+n + " removed!");
    }
    else
        console.log("!!@@## Can find by id:"+n);
};
</script></footer>
原文地址:https://www.cnblogs.com/Searchor/p/13899422.html