简体   繁体   English

如何使用sed在匹配模式时删除多行,并停止到第一个空白行?

[英]How to use sed to delete multiple lines when the pattern is matched and stop until the first blank line?

I am very new to shell script. 我是shell脚本的新手。

How can I delete multiple lines when the pattern is matched and stop deleting until the first blank line is matched? 如何匹配模式时如何删除多行并停止删除直到第一个空行匹配?

You can do this: 你可以这样做:

sed '/STARTING_PATTERN/,/^$/d' filename

This will select all the lines starting from STARTING_PATTERN upto a blank line ^$ and then delete those lines. 这将选择从STARTING_PATTERN到空白行^$所有行,然后删除这些行。

To edit files in place, use -i option. 要编辑文件,请使用-i选项。

sed -i '/STARTING_PATTER/,/^$/d' filename

Or using awk : 或者使用awk

awk 'BEGIN{f=1} /STARTING_PATTERN/{f=0} f{print} !$0{f=1}' filename

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sed,awk或类似 - 如果模式匹配后跟空行,则删除整行和上面的2行 - sed, awk or similar - delete whole line and 2 lines above if pattern matches followed by a blank line 删除空行并使用 bash 和 sed 插入多行 - 在匹配前删除单个空行 - Delete blank line and Inserting multiple lines with bash & sed - deleting single blank line before match sed 如果一行匹配条件,则替换与模式范围匹配的行 - sed to replace lines matched by a pattern range if one line match a condition 如何使用sed删除所有行,直到第一列中的第一个匹配项? - How to use sed to remove all lines until first match in first column? 仅在使用sed或awk将其为空白的情况下删除模式之后的行 - delete a line after a pattern only if it is blank using sed or awk 如何使用Sed删除之前的5行和模式匹配之后的6行? - How to delete 5 lines before and 6 lines after pattern match using Sed? Linux:如何使用sed将从模式开始的行删除到另一个模式 - Linux: How to delete lines starting at a pattern to another pattern using sed 在sed中的匹配模式之间引入新的界线 - Introducing a new line between a matched pattern in sed sed如何删除文件中的前17行和后8行 - sed how to delete first 17 lines and last 8 lines in a file 在使用sed遇到“[ERROR] -17-12-2015”模式之前,如何删除从第1行到第1行的行? - How to delete the lines starting from the 1st line till line before encountering the pattern '[ERROR] -17-12-2015' using sed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM