PHP或Linux Shell:将文本文件多于10行以减少最后10行的最快方法 [英] PHP or Linux Shell: Fastest way to reduce a text file that has more than 10 lines to only have the last 10 lines

查看:45
本文介绍了PHP或Linux Shell:将文本文件多于10行以减少最后10行的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要了解在PHP或Linux Command Shell中以最快的方式将文本文件减少到10行以上的最后10行的方法.我想在此示例中使用10行.

I need to know the fastest way possible, in PHP or Linux Command Shell, to reduce a text file that has more than 10 lines to only have the last 10 lines. I want to use 10 lines for this example.

谢谢:)

推荐答案

将文件缩小到最后一个行

to reduce a file to it's last then lines do

tail -n 10 /path/to/file > /path/to/file.tmp && rm /path/to/file && mv /path/to/file.tmp /path/to/file

说明:

tail 输出文件的最后 n 行.> 将其写入文件.&& 用于链接命令. rm 删除文件. mv 重命名文件(或移动到其他位置).

tail outputs the last n lines of a file. > writes it to a file. && is for chaining commands. rm removes a file. mv renames a file (or moves to a different location).

这篇关于PHP或Linux Shell:将文本文件多于10行以减少最后10行的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆