removing lines between two patterns (not inclusive) with sed

后端 未结 6 480
遇见更好的自我
遇见更好的自我 2020-12-09 20:08

Ok

I know that this is trivial question but: How can i remove lines from files that are between two known patterns/words:

pattern1
garba

6条回答
  •  半阙折子戏
    2020-12-09 21:00

    This is easily done with awk:

    BEGIN { doPrint = 1; }
    /pattern1/ { doPrint = 0; print $0; }
    /pattern2/ { doPrint = 1; }
    { if (doPrint) print $0; }
    

    I've found the sed info is fairly easy reading, with many examples. Same thing for awk.

提交回复
热议问题