douyu7879 2010-06-25 03:58
浏览 12
已采纳

有没有一个版本的tac枪杀内容? (比如zcat)

I am working on a PHP script that needs to read log files in reverse line order.

I currently do the following:

<?php
shell_exec("tac logfile.log > tmpfile.log");
$rFile = fopen("tmpfile.log", "r");
while (!feof($rFile))
{
    //logic 
}
unlink("tmpfile.log");
?>

This works nicely as it switches the order of the lines in the file and I read from the temp file.

However, the log files are going to get massive and I need to keep a lengthy history, so I need to gzip the files up. I found out about 'zcat', and I was hoping that there would be 'ztac' which could plug straight into my code above... but I haven't managed to find it.

Any ideas what the easiest/best way to do this is without needing lots of temp files and a big mess of server commands?

  • 写回答

1条回答 默认 最新

  • dovgqc2648 2010-06-25 04:01
    关注

    I'm thinking

    zcat logfile.log.gz | tac > tmpfile.log
    

    Unzip and reverse lines as two steps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥15 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)