![](/img/trans.png)
[英]SED: delete lines after pattern match while skipping a few lines, then delete the pattern line
[英]How to delete the pattern line and lines after it until whitespace using sed
給定這樣的東西:
圖案
1號線
2號線
3號線
4號線
我想刪除模式及其下的所有內容,直到空白行,有沒有辦法用sed或另一個bash編輯器來做到這一點?
嘗試這個:
sed '/pattern/,/^$/d' File
這是一個awk
解決方案:
awk '/pattern/ {f=1} !f; !NF {f=0}' file
line3
line4
如果空白行確實包含空格,它也將起作用。 ^$
不會。
您可以使用以下語法。
Shell> cat /tmp/list
line1
line2
line3
line4
Shell> cat /tmp/list |sed -e '/line1/,/^$/ d'
line3
line4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.