Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to Prepending a timestamp to each line of output from a command

by choroba (Cardinal)
on Jun 07, 2017 at 09:18 UTC ( [id://1192256]=note: print w/replies, xml ) Need Help??


in reply to How to Prepending a timestamp to each line of output from a command

prepend.pl:
#!/usr/bin/perl use warnings; use strict; use Time::HiRes qw{ time }; my $start = time; while (<>) { printf '%3.7f | %s', time - $start, $_; }

Test run:

for i in {1..10} ; do sleep .2 ; echo $i ; done | prepend.pl

If you want to overwrite a line, don't output "\n" at its end, but use "\r" instead, it will move the cursor to the beginning of the same line.

Update: See Time::HiRes , printf, and Quote and Quote like Operators.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1192256]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found