使用sed删除多行

时间:2014-10-09 07:40:35

标签: bash sed

出于项目的目的,我只能使用sed,而不是grep,awk或print。

如何使用sed删除行开头,比如bbbb或eeee,直到包名称的末尾。 每个包的末尾不是唯一且随机的,行的数量也是随机的,有时是9行,有时是4或5行。

无法完成这项工作。因为我可以控制输入的唯一内容是要启动的包名称,但是如何将其删除到该包的末尾。

            Package: aaaa
            Status: 
            Priority: 
            Section: 
            Installed-Size: 
            Maintainer: 
            Architecture: 
            Version: 
            Depends:
            Description: 
            Name: 
            Icon

            Package: bbbb
            Status: 
            Priority: 
            Section: 
            Installed-Size: 
            Maintainer: 
            Architecture: 
            Version: 
            Depends:
            Description: 
            Name: 
            Homepage: 


            Package: cccc
            Status: 
            Priority: 
            Section: 
            Depends:
            Description: 
            Name: 
            Homepage: 


            Package: dddd
            Status: 
            Priority: 
            Section: 
            Installed-Size: 
            Maintainer: 
            Architecture: 
            Version: 
            Depends:
            Description: 
            Name: 
            Homepage: 


            Package: eeee
            Status: 
            Priority: 
            Section: 
            Installed-Size: 
            Maintainer: 
            Architecture: 
            Version: 




            Package: dddd
            Status: 
            Priority: 
            Section: 
            Installed-Size: 
            Maintainer: 
            Architecture: 
            Text: 




            Package: ffff
            Status: 
            Priority: 
            Section: 
            Installed-Size: 
            Maintainer: 
            Architecture: 
            Version: 
            Depends:
            Description: 
            Name: 
            Link: 



            Package: ggg
            Status: 
            Priority: 
            Section: 
            Installed-Size: 
            Depends:
            Description: 
            Name: 
            Homepage: 

2 个答案:

答案 0 :(得分:1)

sed '/Package: bbbb/,/^ *$/d' YourFile

假设您的bbbb是包的名称(样本中没有出现其他情况),并且paragraphe以空行结束(仅允许为空格char)

答案 1 :(得分:1)

awk '/bbbb/{b=1;next}b==1&&/Package/{b=0}b==0' input.txt

bbbb删除行,直到找到下一个Package文本