Delete first line of file if it's empty

后端 未结 5 1201
再見小時候
再見小時候 2021-02-07 22:06

How can I delete the first (!) line of a text file if it\'s empty, using e.g. sed or other standard UNIX tools. I tried this command:

sed \'/^$/d\' < somefile         


        
5条回答
  •  不要未来只要你来
    2021-02-07 22:54

    Using sed, try this:

    sed -e '2,$b' -e '/^$/d' < somefile
    

    or to make the change in place:

    sed -i~ -e '2,$b' -e '/^$/d' somefile
    

提交回复
热议问题