How to select lines between two marker patterns which may occur multiple times with awk/sed

前端 未结 9 1194
离开以前
离开以前 2020-11-22 04:41

Using awk or sed how can I select lines which are occurring between two different marker patterns? There may be multiple sections marked with these

9条回答
  •  有刺的猬
    2020-11-22 05:09

    something like this works for me:

    file.awk:

    BEGIN {
        record=0
    }
    
    /^abc$/ {
        record=1
    }
    
    /^mno$/ {
        record=0;
        print "s="s;
        s=""
    }
    
    !/^abc|mno$/ {
        if (record==1) {
            s = s"\n"$0
        }   
    }
    

    using: awk -f file.awk data...

    edit: O_o fedorqui solution is way better/prettier than mine.

提交回复
热议问题