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

后端 未结 4 593
感动是毒
感动是毒 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:16

    This is what you want:

    $ sed '1{/"GH"/!d}' file
    
    0 讨论(0)
  • 2021-01-05 18:16
    sed '1{/<pattern>/{/GH/!d}}' input
    

    The error in your expression can be fixed like this:

    sed '1{/<pattern>/d}' input
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-05 18:25

    This might work for you:

    sed -e '1!b' -e '/GH/!d' file
    
    0 讨论(0)
提交回复
热议问题