coreutils
[Top][All Lists]
Advanced

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

Re: 'date' enhancement: flush in format string


From: Eric Blake
Subject: Re: 'date' enhancement: flush in format string
Date: Thu, 11 Aug 2011 16:20:30 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11

On 08/11/2011 03:54 PM, Darko Veberic wrote:
then it occurred to me that i could use "date" as a co-process in awk
directly, spawning "date" only once and using the date's -f redirected
to standard input:

BEGIN{d="date -u -f- +%s"}
{print $1 |& d; d |& getline t; print t,...}
END{close(d)}

Interesting idea to use a coprocess!


unfortunately "date" is not flushing its output after each input line is
processed, resulting in awk's getline deadlock.

enhancement request:
is it possible to add another % symbol to the date output format, say %f

No.  Format symbols are scarce, and %f is already taken.

But there some other viable options.

One idea is to change date to always flush after every line. But I don't know if this would hurt performance when the flushing is not needed, and you'd have the same problem as with your %f proposal - namely, it would take a while for the code to propagate onto your machine.

Another idea is to use something that already exists. date uses stdio, so the stdbuf utility (also part of coreutils) can be used to force date into line-buffered mode. So, try "stdbuf -o L date -u -f- +%s" as your command instead of raw date.

Also, how uniform is the date input already present in the input file? If it is sufficiently uniform, can you just use awk's own date parsing utilities? It comes with a few builtins that may be able to already handle your needs without spawning external processes.

--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

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