使用linuxsbash或命令行,我需要在文件中找到特定的字符串,并删除该行和这些行,直到空白。
我的文件:

geo_ws:
    resource: "@GeoWSBundle/Controller/"
    type:     annotation
    prefix:   /

mappublic:
    resource: "@MapPublicBundle/Controller/"
    type:     annotation
    prefix:   /map/ws

webpublic:
    resource: "@WebPublicBundle/Controller/"
    type:     annotation
    prefix:   /public

map:
    resource: "@MapBundle/Controller/"
    type:     annotation
    prefix:   /map

geo:
    resource: "@GeoBundle/Controller/"
    type:     annotation
    prefix:   /geo

ws:
    resource: "@WSBundle/Controller/"
    type:     annotation
    prefix:   /ws

web:
    resource: "@WebBundle/Controller/"
    type:     annotation
    prefix:   /

所以我需要找到“地图:”,并清除所有这4行,直到下一条白线。
我试过用seed,但就是想不出来。

最佳答案

空记录分隔符表示记录由空行分隔:

$ awk -v RS='' -v ORS='\n\n' '!/^map/' file
geo_ws:
    resource: "@GeoWSBundle/Controller/"
    type:     annotation
    prefix:   /

webpublic:
    resource: "@WebPublicBundle/Controller/"
    type:     annotation
    prefix:   /public

geo:
    resource: "@GeoBundle/Controller/"
    type:     annotation
    prefix:   /geo

ws:
    resource: "@WSBundle/Controller/"
    type:     annotation
    prefix:   /ws

web:
    resource: "@WebBundle/Controller/"
    type:     annotation
    prefix:   /

关于linux - 逐行查找文字,然后从bash中删除该行到另一行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35557562/

10-13 06:42