~$ /usr/bin/time -f "%e: " echo test
test
0.00:
I want the output to be
0.00: test
How would I accomplish this?
~$ /usr/bin/time -f "%e: " echo test
test
0.00:
I want the output to be
0.00: test
How would I accomplish this?
Unless you're asking for some form of time travel, you would need to capture the output and rearrange it. time
outputs its result on standard error.
$ /usr/bin/time -f "%e: " echo test >so 2>se; echo $(<se) $(<so)
0.01: test
g++
will send any output (since it only produces output on error) to stderr
. It's complex enough that you would want to use a wrapper script. Also, are you thinking of wrapping the (normally nonexistent) output from g++
, or the echoed command from make
? The latter can't easily be done while echoing the actual command.
Apr 21, 2012 at 0:39
make
pattern rules. See gnu.org/software/make/manual/make.html#Pattern-Rules for gmake
; it's similar for other versions of make
although specific details will differ.
Apr 21, 2012 at 1:00
As geekosaur's answer says, time prints to stderr, and your command prints to stdout. And time waits for your command to finish before writing its output. I think you should try the program sponge
from the package moreutils
, like this:
/usr/bin/time -f "%e: " echo test | sponge
Sponge is a program which soaks up all the input and writes it when the input is closed (i.e. the previous program terminates). The above works because time will print to stderr when echo finishes, and echo's stdout will be soaked up by the sponge, which will only wring itself out when the left hand side finishes. So this does pretty much what you want as far as I can tell, though I wasn't able to test it for complete accuracy because my system's /usr/bin/time doesn't support the -f option.
(/usr/bin/time echo test | sponge) 2>&1
Apr 21, 2012 at 8:00
I don't think that's possible. One way of doing it is to capture the output into a variable and manipulate it.