【发布时间】:2019-04-25 06:04:09
【问题描述】:
我有一个文件,内容如下:
## this must go ##
## also
this
must go
##
hello world
##and this one
too##
我想删除##之间的所有内容,包括多行,所以我只剩下hello world
这只会删除一行中的部分:
sed -i.bak 's/##.*##//g' myfile
如何也删除多行内容?
P.S 我在 MAC 上
【问题讨论】:
-
可能 perl 解决方案会更简单:
perl -0pe 's/##.*?##\R*//gs' file > newfile(demo)。 -
@WiktorStribiżew 嘿,您的解决方案效果最好 - 发布您的答案,我会接受。谢谢!