在shell程序中用vim删除掉文件的最后一行

怎样用shell脚本删除掉文件的最后一行
网上大家多有讨论
方法也多多
比如用sed
用tail
用head
等等等等
但貌似都需要先把输出定向到一个临时文件
然后再删除原有文件
最后再把临时文件mv成原文件
后来找到一种方法
利用vim和重定向
直接在shell里实现
代码是这样的:

vim xxxx.txt 2>/dev/null < G
dd
:x!
END

如此而已
呵呵

2 Responses to “在shell程序中用vim删除掉文件的最后一行”

  1. …小文件行 大文件你这样就死了

  2. 大文件?
    这倒没考虑过
    因为这个主要是为了方便批量更改配置文件
    配置文件不会太大吧
    那大文件应该怎么改呢?

Discussion Area - Leave a Comment




*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word