Regex with sed, search across multiple lines

前端 未结 2 1922
南笙
南笙 2021-02-09 20:59

I\'d like to concatenate a few lines, perform a regex match on them and print them. I tried to do that with sed.

Namely, I used:

cat add | sed -rn \'/FIR         


        
2条回答
  •  误落风尘
    2021-02-09 21:45

    sed -n '/FIRST_LINE_REGEX/,/LAST_LINE_REGEX/p' add | sed -n '/FIRST_LINE_REGEX/ b check; H; $ b check; b; :check; x; /SOME_REGEX/p'

    The motivation of the second pipe part comes from here: https://stackoverflow.com/a/6287105/992834

    Edit: Amended for when SOME_REGEX is in between.

提交回复
热议问题