Re: suggested addition to 'date'



On 2006-08-11 20:19, Sam Leffler <sam@xxxxxxxxx> wrote:
Julian Elischer wrote:
At various times I've wanted to add timestamps to logfiles as they are
generated..

usually this has involved perl or something to do it.

pbj% ls | sed -e "s/^/`date +'%+: '`/"
Fri Aug 11 20:18:05 PDT 2006: Desktop
Fri Aug 11 20:18:05 PDT 2006: Desktop DB
Fri Aug 11 20:18:05 PDT 2006: Desktop DF
Fri Aug 11 20:18:05 PDT 2006: Documents
Fri Aug 11 20:18:05 PDT 2006: Library
Fri Aug 11 20:18:05 PDT 2006: Movies
...

Unfortunately this won't work. The `backquoted` command is expanded
only once -- before the rest of the command-line runs:

$ for sec in 1 2 3 4 5 ; do echo "second $sec" ; sleep 1; done | sed -e "s/^/`date +'%+: '`/"
Sat Aug 12 06:38:03 EEST 2006: second 1
Sat Aug 12 06:38:03 EEST 2006: second 2
Sat Aug 12 06:38:03 EEST 2006: second 3
Sat Aug 12 06:38:03 EEST 2006: second 4
Sat Aug 12 06:38:03 EEST 2006: second 5
$

Using Perl and ``Time::HiRes qw(gettimeofday)'' is the best trick I've
found so far for this sort of thing :-/

_______________________________________________
freebsd-current@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Wait for background processes to complete
    ... To be able to execute commands in the background and wait for their ... The documentation I am referring to is http://perldoc.perl.org/. ... You can run a command in the background with: ... There is a general problem with perl documentation: ...
    (comp.lang.perl.misc)
  • Re: Need help writing script to find files by date
    ... It sounds like you don't have Perl installed. ... Command not found.', ... The +100 means "files with modification time older than 100 days ago", ... If you want to sort the files by age, then use the stat command to ...
    (comp.sys.mac.system)
  • Re: Perl For Amateur Computer Programmers
    ... >professional computer programmers could use with the same ease as Basic. ... >Perl For Amateur Computer Programmers ... Also, taking into account that you're appealing to "scientists", it ... Also, as a side note, you seem to use the noun "command" in a naive ...
    (comp.lang.perl.misc)
  • Obtaining complete Unix command line that evoked script as string
    ... If there is a more appropriate list for this, let me know; the other perl lists I've seen seem to specialised for this. ... Note this is not just the arguments of the call to the script, but everything including pipes and redirects, etc., e.g. ... Ideally the perl interpreter would grab the complete command line as its evoked and I'd access this via a variable. ...
    (perl.beginners)
  • Thanks for the comments Jan. 25, 2006
    ... "shadow" operating system which is running behind Windows. ... Perl can then collect data from that program and do ... that by sending longer strings etc. to the Windows clipboard and then having ... SendKeysuse a Ctrl V command to paste the information to the text editor ...
    (comp.lang.perl.misc)