You are not logged in.
Pages: 1
I want to be able to filter time output so that I would only output numbers for real time.
Typical output of time is :
user@user-VirtualBox:~$ time gzip -fc -1 rafale.bmp > rafale.bmp.gz
real 0m0.331s
user 0m0.156s
sys 0m0.060s
By using grep, to filter for "real", I get this:
armen@armen-VirtualBox:~$ (time gzip -fc -1 rafale.bmp > rafale.bmp.gz) 2>&1 | grep real
real 0m0.280s
How can I get only the 0.280? without "real"
Last edited by kdar (2012-05-18 14:27:28)
Offline
<your command> | awk '/real/ {print $2}'
Or if you want to also drop the minutes, the 'm' and the 's':
<your command> | awk '/real/ {gsub(/0m/,"",$2);gsub(/s/,"",$2);print $2}'
Last edited by Trilby (2012-05-18 14:40:14)
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
This'll cut the 0m0 but not the 's' - you'll need gsub as shown by Trilby for that (I think).
<your command> | awk -Fm '/real/ {print $2}'
Last edited by skanky (2012-05-18 14:49:14)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Thanks everyone.
Does anyone know if I should avoid using time -p? Will it give different results than time?
help time states that -p prints the timing summary in the portable Posix format, however, will the result differ from those of time (without using -p)?
Offline
I don't know much about time ... just ask anyone who's scheduled meetings I'm supposed to show up to! ... ;o)
But you could try both. It seems to me the '-p' drops the minutes, the 'm' and the 's'. So if you just want a clean number, use the '-p' options and use the simpler awk command.
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Offline
well, if it just for reformatting output, I guess this is ok. But I worry if it calculates real time somehow different with -p.
Offline
Pages: 1