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

前端 未结 9 1299
离开以前
离开以前 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:31

    sed '/^abc$/,/^mno$/!d;//d' file
    

    golfs two characters better than ppotong's {//!b};d

    The empty forward slashes // mean: "reuse the last regular expression used". and the command does the same as the more understandable:

    sed '/^abc$/,/^mno$/!d;/^abc$/d;/^mno$/d' file
    

    This seems to be POSIX:

    If an RE is empty (that is, no pattern is specified) sed shall behave as if the last RE used in the last command applied (either as an address or as part of a substitute command) was specified.

提交回复
热议问题