[英]How to delete a block of text in a file Shell Script?
我有以下場景我有一段文字和示例
basketball:
ball: round
因為我不確切知道籃球里面有什么:但我喜歡刪除里面的所有內容示例:
men:
height: 170
athlete: basketball
women:
height:180
athlete: basketball
我只想刪除 men 塊忽略此鍵上方或下方的任何內容
下面的 AWK 腳本filter.awk
刪除了所有包含籃球的男性部分。 你是這個意思嗎? 使用awk -f filter.awk input.txt
運行。
/^[A-Za-z0-9]/ {
if (sectionWanted) {
printf "%s", section
}
sectionWanted = 1
section = ""
sectionName = $1
}
/basketball/ && sectionName == "men:" {
sectionWanted = 0
}
{
section = section $0 "\n"
}
END {
if (sectionWanted) {
printf "%s", section
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.