Operating System - HP-UX
1829161 Members
10241 Online
109986 Solutions
New Discussion

how can I get correct output of time command

 
YatinC
Occasional Contributor

how can I get correct output of time command

time my_command gives me correct output. but time my_command|grep something gives me output which also includes time taken by grep. How can i avoid this.

[root@XXXXX]#time vxdisk list
real 0m0.013s
user 0m0.003s
sys 0m0.003s

[root@XXXXX]#time vxdisk list|sleep 5|grep real

real 0m5.002s
user 0m0.004s
sys 0m0.004s
[root@XXXXX]#

3 REPLIES 3
Steven E. Protter
Exalted Contributor

Re: how can I get correct output of time command

Shalom,

Break the command into two parts.

time vxdisk list > file
grep real file

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Patrick Wallek
Honored Contributor

Re: how can I get correct output of time command

Try using /usr/bin/time

Steven Schweda
Honored Contributor

Re: how can I get correct output of time command

First, "sleep" is not a filter. Piping
output through "sleep" does not work.

Sub-shell?

( time vxdisk list ) 2>&1 | grep real


"man time":

[...]
The times are printed on standard error.
[...]

I assume that you wanted the "grep" to work.

Of course, it also says this:

Note that the shell also has a keyword time that times an entire
pipeline if used anywhere in the pipeline, unlike time(1) command
which times a particular command if used in a pipeline.

So, you might want something more like:

/usr/bin/time vxdisk list 2>&1 | grep real

(Or, when you see the results, you might
not.)