Removing last blank line

前端 未结 5 1513
礼貌的吻别
礼貌的吻别 2021-02-12 14:50

There is a para break at the end of my .csv file. I tried to remove the blank line that is at the end of the file using the following command.

sed -i \'/^$/d\' c         


        
5条回答
  •  暖寄归人
    2021-02-12 15:21

    Try ${/^$/d;} this will only match an empty line if it is the last line of the file.

    I tried it with sed (GNU sed) 4.2.2 and got all blank lines deleted not only the empty line if it is the last line of the file.

    I found the following Command, that worked for myself that does the Job.

    sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'
    

    This Command is from a Collection of useful SED-Oneliners: http://sed.sourceforge.net/sed1line.txt

提交回复
热议问题