I use something like that every day -- I have a script called notch.pl that outputs a blank line and the time after a new line of output arrives if it's a different minute that the previous line's time.

Here's the code:

#!/usr/bin/perl -w # Notch out time when lines from 'tail -f' arrive so that lines # from different minutes are separated by a timestamp. use strict; { my $lastMinute = (localtime)[1]; while(<>) { my $thisLine = $_; my $thisMinute = (localtime)[1]; if ( $thisMinute != $lastMinute ) { $lastMinute = $thisMinute; print "\n"; print scalar localtime; print "\n"; } print $thisLine; } }
I probably could use File::Tail as merlyn suggests but just threw it together because trying to readh read the tail of a log file is head hard enough -- this just breaks it up a little.

Based on the amount of traffic that I see, I don't worry too much about it using an extra pipe or process.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Update Correct two typos .. the first of which I made again, and had to go back and fix again.


In reply to Re: Using pipe and reading from the stdin by talexb
in thread Using pipe and reading from the stdin by mellin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.