Bash 如果遇到特定单词,请删除awk中的块

Bash 如果遇到特定单词,请删除awk中的块,bash,sed,awk,Bash,Sed,Awk,我想使用awk只打印出Start和End行之间没有单词complete的块 我是根据以前的文章写这部分的,但问题是我的行不是以start和end开头的。我可以交换它们,并把这些记录放在行首,但如果有人知道另一种选择,那将不胜感激。谢谢大家! 下面是如何在awk cat file Hello Start some data more End Data Start Yes Here is more This is incomplete Not my day End 如果不包含不完整 一些更具

我想使用
awk
只打印出
Start
End
行之间没有单词
complete
的块

我是根据以前的文章写这部分的,但问题是我的行不是以
start
end
开头的。我可以交换它们,并把这些记录放在行首,但如果有人知道另一种选择,那将不胜感激。谢谢大家!


下面是如何在
awk

cat file
Hello
Start
some data
more
End
Data
Start
Yes
Here is more
This is incomplete
Not my day
End
如果不包含
不完整


一些更具可读性的:

awk '
    $0~start    {                       # If `Start` is found, do:
                f=1}                    # Set flag `f` to `1`
    f           {                       # If flag `f` is true do:
                s=s?s"\n"$0:$0          # Create block of data. (Take care of start correctly)
                if ($0~/incomplete/)    # If line does contain `incomplete` do:
                    f=s=0}              # Clear block of data `s` and clear flag `f`
    $0~end && f {                       # If `End` is found and flag `f` is true, do:
                print s                 # Print block of data `s`
                f=s=0}                  # Clear block of data `s` and clear flag `f`
    ' start="$start" end="$end"         # Read `start` and `stop` from variable
    file                                # Name of input file

你的输入看起来是什么样子的?告诉我们两个你的块没有开始和结束的单词并不是特别有用。你大概可以猜到什么是有用的。。。
cat file
Hello
Start
some data
more
End
Data
Start
Yes
Here is more
This is incomplete
Not my day
End
awk '/Start/ {f=1} f {s=s?s"\n"$0:$0;if ($0~/incomplete/) f=s=0} /End/ && f {print s;f=s=0}' file
Start
some date
more
End
awk '
    $0~start    {                       # If `Start` is found, do:
                f=1}                    # Set flag `f` to `1`
    f           {                       # If flag `f` is true do:
                s=s?s"\n"$0:$0          # Create block of data. (Take care of start correctly)
                if ($0~/incomplete/)    # If line does contain `incomplete` do:
                    f=s=0}              # Clear block of data `s` and clear flag `f`
    $0~end && f {                       # If `End` is found and flag `f` is true, do:
                print s                 # Print block of data `s`
                f=s=0}                  # Clear block of data `s` and clear flag `f`
    ' start="$start" end="$end"         # Read `start` and `stop` from variable
    file                                # Name of input file