excluding first and last lines from sed /START/,/END/

后端 未结 5 1367
轮回少年
轮回少年 2020-12-24 01:18

Consider the input:

=sec1=
some-line
some-other-line

foo
bar=baz

=sec2=
c=baz

If I wish to process only =sec1= I can for example comment

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 01:31

    Another way would be

    sed '/begin/,/end/ {
           /begin/n
           /end/ !p
         }'
    

    /begin/n -> skip over the line that has the "begin" pattern
    /end/ !p -> print all lines that don't have the "end" pattern

    Taken from Bruce Barnett's sed tutorial http://www.grymoire.com/Unix/Sed.html#toc-uh-35a

提交回复
热议问题