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

标签 linux bash command-line

使用 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/

相关文章:

linux - Weasyprint输出格式问题-如何使用CSS @page?

linux - 这个命令 ls 的作用是什么。 | xargs -i -t cp ./{} $1

ruby-on-rails - RVM 正在加载错误版本的 ruby​​?

bash - 使用命令的结果作为 bash 中的参数?

Javascript 作为命令行可调用脚本语言

bash - 为什么在可执行文件或脚本名称之前需要 ./(点斜杠)才能在 bash 中运行它?

linux - 使用BioAPI转换比较两张指纹位图图像

c - 为什么 ififd 的 pci linux 实现使用 "platform_driver"而不是 "pci_driver"?

linux - 无法在守护进程模式下运行 docker?

Linux - Grep 和进程替换