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

前端 未结 8 1361
眼角桃花
眼角桃花 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:50

    Here's another using ex, which I find not as cryptic as the sed solution:

     printf '%s\n' '$' 's/.$//' wq | ex somefile
    

    The $ goes to the last line, the s deletes the last character, and wq is the well known (to vi users) write+quit.

提交回复
热议问题