I need to delete the last 2 characters from a text file in shell script. Any idea about how I can do it?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Delete the last two characters on the last line only with sed
:
$ sed '$s/..$//' file
If you are happy with changes then use -i
to store them back to the file:
$ sed -i '$s/..$//' file
If you wanted to delete the last two characters on every line it would be:
$ sed 's/..$//' file
Again use -i
to store the changes back to the file:
$ sed -i 's/..$//' file