我有arounf 50个html文件,必须用空行替换完整性和sha部分。
在所有html文件中,我们都可以使用
找到常见的JS。<script crossorigin='anonymous' integrity='sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q' src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js'></script>
我只需要用
代替<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js'></script>
我尝试使用sed
命令
sed -i -e 's|<script crossorigin='anonymous' integrity='sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q' src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js'></script>|<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js'></script>|g' *.html
它没有替代任何
答案 0 :(得分:0)
如下所示,使用给定的字符串,并考虑到要在第一个和最后一个空格之间删除所有内容,并且在URL字符串中没有空格,因此很简单,
< test.txt sed 's/ .* / /'
<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js'></script>
而test.txt包含原始字符串。
答案 1 :(得分:-1)
我终于设法弄清楚了这一点,并设法替换了所有html文件中的js
sed -i -e "s|<script crossorigin='anonymous' integrity='sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q' src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js'></script>|<script src='https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js'></script>|" *.html ```