我意外地在许多服务器上分配了一行到/ etc / crontab,我注意到这行有一个错字,我需要在所有服务器上更改它。
另一个select是修复错字,而不是只删除最后一行
sed -i '$ s/typotext/correcttext/ /var/spool/cron/user
您应该可以直接编辑crontab文件,以便更新版本的cron,因为它会在非常短的时间内检查更改。
如果你的sed支持就地编辑,那么,
sed -i '$d' file
如果没有,你需要使用复合命令,比如,
cat file | sed '$d' > newfile; mv newfile file
用head
user@host$ cat <<EOF > test.txt 1 2 3 4 EOF user@host$ head -n -1 test.txt | sponge test.txt user@host$ cat test.txt 1 2 3 user@host$
您可以在Ex模式下使用Vim:
ex -sc 'd|x' /etc/crobtab
d删除行
保存并退出
看到这个论坛上的文章在unix.com的答案:
http://www.unix.com/shell-programming-scripting/25027-delete-last-line.html
sed -e'$ d'input.file> output.file
要么
head – $(( wc -l file | awk '{print $1}' – 1))file