delphi programming forums mysql charset mget recursive synonimos
free ventrilo servers hosting cs javascript delay python find in list
Back Forum New
abstract:

more timefile_2.txt
-rw-r--r--   1 root     other          0 Jun 21 17:13 test123.txt
-rw-r-----   1 sybase other   2096629760 Jun 24 10:01 hello.txt
-rw-r--r--   1 root     other          0 Jun 24 10:58 timefile_2.txt

*********************************************************
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


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:
bash-2.05#
( time ls -ltr) | tail -3 > timefile_1.txt
real    0m0.008s
user    0m0.000s
sys     0m0.010s

I then looked at the contents of the file
timefile_1.txt
and I saw this :
bash-2.05#
more timefile_1.txt
-rw-r--r--   1 root     other        201 Jun 24 10:58 abc123.txt
-rw-r-----   1 sybase   sybase   2096629760 Jun 24 11:01 tempdb_dev
-rw-r--r--   1 root     other          0 Jun 24 11:42 timefile_1.txt
**********************************************************
So I experimented some more :
bash-2.05# ( time ls -ltr) | tail -3 > timefile_2.txt 2>&1

real    0m0.009s
user    0m0.010s
sys     0m0.000s

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
bash-2.05#
more timefile_2.txt
-rw-r--r--   1 root     other          0 Jun 21 17:13 test123.txt
-rw-r-----   1 sybase other   2096629760 Jun 24 10:01 hello.txt
-rw-r--r--   1 root     other          0 Jun 24 10:58 timefile_2.txt
*********************************************************
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

TOP

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

TOP


Originally Posted by vgersh99
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
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

TOP

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 :
bash-2.05#(time ls -ltr) 2> time.txt 1>/dev/null ; tail -3 time.txt | awk '{print $2}' | awk -Fm '{print $1,$2}' | awk -Fs '{print $1,$2}'
The output of the above command :
0 0.008
0 0.000
0 0.010
I would want to initially store 0 in var1 and 0.008 in var2 so I could do some other calculations.

TOP

abstract:

more timefile_2.txt
-rw-r--r--   1 root     other          0 Jun 21 17:13 test123.txt
-rw-r-----   1 sybase other   2096629760 Jun 24 10:01 hello.txt
-rw-r--r--   1 root     other          0 Jun 24 10:58 timefile_2.txt

*********************************************************
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


Ok I think I figured out how to avoid writing the output to a file :
(time ls -ltr) 2>&1 1>/dev/null | tail -3  | awk '{print $2}' | awk -Fm '{print $1,$2}' | awk -Fs '{print $1,$2}'
Gives the following output :
0 0.009
0 0.000
0 0.010

TOP


Code:
  1. (time ls -ltr) 2>&1 1>/dev/null | tail -3 | sed 's/.*\([0-9][0-9]*\)m\(.*\)s$/\1 \2/'
Copy Code

TOP


Originally Posted by vgersh99
Code:
  1. (time ls -ltr) 2>&1 1>/dev/null | tail -3 | sed 's/.*\([0-9][0-9]*\)m\(.*\)s$/\1 \2/'
Copy Code
Hey thanx....that code seems better.



more timefile_2.txt
-rw-r--r--   1 root     other          0 Jun 21 17:13 test123.txt
-rw-r-----   1 sybase other   2096629760 Jun 24 10:01 hello.txt
-rw-r--r--   1 root     other          0 Jun 24 10:58 timefile_2.txt

*********************************************************
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

TOP

Back Forum