我有一堆没有换行符的 html。我想在任何 </p>
之后添加一两个换行符标签。
我认为这可以做到,但它似乎没有添加空行:
echo "<p>first line of text</p><p>second line of text</p>" | sed 's:</p>:</p>\n:g' > file.html
最佳答案
这不起作用,因为非 GNU 版本的 sed
不支持 \n
。解决这个问题的一个聪明方法是在将其交给 sed 之前使用 bash shell 来扩展它。只要您使用 bash
作为解释器,这应该适用于 sed
的所有版本
$ sed $'s:</p>:&\\\n:g' <<<'<p>first line of text</p><p>second line of text</p>'
<p>first line of text</p>
<p>second line of text</p>
关于unix - 在每个 </p> 之后添加换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9425020/