gpt4 book ai didi

linux - 按文本查找行并从该行删除到 bash 中的其他行

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:56:49 26 4
gpt4 key购买 nike

使用 linux bash 或命令行,我需要在文件中找到特定的字符串并删除该行和直到出现空格的行。

我的文件:

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: /

所以我需要找到“ map :”,并清除所有这 4 行,直到下一个白行。

我试过使用种子,但我就是想不通。

最佳答案

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

$ 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com