[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Piping tail -f to fold: tail -f log.txt | fold

From: Philip Durbin
Subject: Piping tail -f to fold: tail -f log.txt | fold
Date: Fri, 09 Jan 2009 09:46:35 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20081209 Red Hat/1.0.9-32.el4 SeaMonkey/1.0.9

To word wrap the output of a growing log file I tried. . .
$ tail -f log.txt | fold -s
. . . and it works fine on NetBSD and Mac OS X, but on the two Linux distributions I tried (Red Hat and SUSE) I get no output.

As a work around for Linux I can combine tail without -f and watch. . .
$ watch "tail log.txt | fold -s"
. . . but because I'm likely to miss some lines, I threw together a Perl script instead:

use strict;
use warnings;
use File::Tail;
use Text::Wrap;
$Text::Wrap::columns = 72;
my $file = File::Tail->new('/tmp/log.txt');
while ( defined( my $line = $file->read ) ) {
    print wrap( '', '', $line );

Despite my workarounds, I'm still left wondering. . .

Can piping tail -f to fold be made to work on Linux the way it works on BSD?

If not, can anyone please explain the difference in the implementation of fold?

Thanks in advance!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]