|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||||
|
||||||
|
Controlling "output" from UNIX time commmand
I have a problem controlling the output from the UNIX time command, for some strange reason the "output" (specifically the last 3 lines of the output) seems like it can only be directed to the screen, no matter what I do:
Take for example I tried this: Quote:
I then looked at the contents of the file timefile_1.txt and I saw this : Quote:
********************************************************** So I experimented some more : Quote:
As you can see below the last 3 lines of the ls -ltr command has been redirected to the timefile_2.txt file, I need the above 3 lines from the time command Quote:
********************************************************* My aim is to capture the results (all 3 results) of the time command (I need to do some arithmetic calculations on the values) I'm working on a SunOS 5.9 Generic_112233-12 sun4u sparc SUNW,Sun-Fire-V440 server |
|
#2
|
|||
|
|||
|
why are you doing 'tail -3'?
this works fine for me [ksh on Solaris 7] - capturing both the 'ls' and the 'time' in the same file. (time ls -l) 1> /tmp/time 2>&1 |
|
#3
|
|||
|
|||
|
Quote:
I don't want to capture the output from the ls -l command only the time. Thanx though for your suggestion. This is what works : (time ls -ltr) 2> time.txt 1>/dev/null |
|
#4
|
||||
|
||||
|
I have another question....would it be possible for me to manipulate the output of the time command without first dumping it to file ? The thing is, I really don't want to create the time.txt file. What I would want to do is isolate the two numeric sections of the output and store them in variables var1 and var2 respectively (note that this would be done inside a loop inside a ksh script):
The following commands isolates the numeric portions of the output that I want : Quote:
The output of the above command : Quote:
I would want to initially store 0 in var1 and 0.008 in var2 so I could do some other calculations. |
|
#5
|
||||
|
||||
|
Ok I think I figured out how to avoid writing the output to a file :
Quote:
Gives the following output : Quote:
|
|
#6
|
|||
|
|||
|
Code:
(time ls -ltr) 2>&1 1>/dev/null | tail -3 | sed 's/.*\([0-9][0-9]*\)m\(.*\)s$/\1 \2/' |
|
#7
|
|||
|
|||
|
Quote:
Hey thanx....that code seems better. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Controlling "output" from UNIX time commmand |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|