Is there a tac version that destroys content? (e.g. zcat)

I am working on a PHP script that should read the log files in reverse order.

I am currently doing the following:

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

This works well, as it switches the order of the lines in the file, and I am reading from a temporary file.

However, the log files will be massive, and I need to keep a long history, so I need gzip files up. I found out about "zcat" and I was hoping there would be a "ztac" that could connect directly to my code above ... but I could not find it.

Any ideas what the easiest / best way to do this does not require a lot of temporary files and a big mess of server commands?

+3
1

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

.

+6

Source: https://habr.com/ru/post/1751697/


All Articles