在文件中多行填充

时间:2019-02-27 16:40:03

标签: bash shell sed

我在许多文件中都有这些行要删除,但是CentoOS上的sed命令不能替换整个句子。

文字示例:

<!-- insert this +1 -->
<div style="float:left"><g:plusone size="medium" href="http://xxxxx/xx.com"></g:plusone></div>
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
{lang: 'it'}
</script>


sed '/<\!-- insert this +1 -->/d' FILENAME.html
sed '/<div style=\"float:left\"><g:plusone size=\"medium\" href=\"http:\/\/xxxxx\/xx.com\"><\/g:plusone><\/div>/d' FILENAME.html
sed '/"<script type=\"text\/javascript\" src=\"https:\/\/apis.google.com\/js\/plusone.js\">/d' FILENAME.html
sed '/{lang: 'it'}/d' FILENAME.html
sed '/<\/script>/d' FILENAME.html

单个命令有效,但替换文件中的</script>和其他匹配项。

我用| / -e / perl -0pe / ''""的许多组合进行了测试,但这是行不通的。如何通过仅删除该部分来替换它?

1 个答案:

答案 0 :(得分:0)

就这么简单

只需检查该行的行号,然后使用以下命令将其删除。 例如,它们在第7行和第9行:

sed '7,9d' FILENAME.html