How can I remove the last character of a file in unix?

前端 未结 8 1375
眼角桃花
眼角桃花 2020-11-30 05:35

Say I have some arbitrary multi-line text file:

sometext
moretext
lastline

How can I remove only the last character (the e, not the newline

8条回答
  •  感动是毒
    2020-11-30 05:47

    After a whole bunch of playing around with different strategies (and avoiding sed -i or perl), the best way i found to do this was with:

    sed '$! { P; D; }; s/.$//' somefile
    

提交回复
热议问题