如何删除所有,但该文件中的最后10行? [英] How can I remove all but the last 10 lines from a file?
本文介绍了如何删除所有,但该文件中的最后10行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能只保留一个简单的shell命令的最后10行的行?
Is it possible to keep only the last 10 lines of a lines with a simple shell command?
tail -n 10 test.log
提供了正确的结果,但我不知道如何修改test.log中本身。以及
delivers the right result, but I don't know how to modify test.log itself. And
tail -n 10 test.log > test.log
不起作用。
推荐答案
您可以使用临时文件做到这一点。
You can do it using tempfile.
tail -n 10 test.log > test1.log
mv test1.log test.log
这篇关于如何删除所有,但该文件中的最后10行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文