How to conditionally remove first line only with sed when it matches?

后端 未结 4 592
感动是毒
感动是毒 2021-01-05 17:37

Can I use sed to check the first line of some command\'s output (to stdout) and delete this very first line if it matches a certain pattern?

Say, the co

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-05 18:20

    You want to reference the 1st line, then say delete:

    $ sed '1 d' file
    

    No need for any pattern if you know which line you want to delete.

    With a pattern, use this syntax:

    $ sed '0,/pattern/ d' file
    

提交回复
热议问题