Changing the format of the unix time command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing the format of the unix time command
# 1  
Old 07-26-2011
Changing the format of the unix time command

Hello.
I use time in order to calculate the execution time of a program.

The output format is:

Code:
real   0m0.059s
user  0m0.028s
sys    0m0.004s

Is there a simple and elegant way to add user and sys together, and convert to milliseconds?

Thanks a lot!

Last edited by radoulov; 07-26-2011 at 04:02 PM.. Reason: Code tags, please!
# 2  
Old 07-26-2011
It's part of the shell, so it depends on your system and shell.
# 3  
Old 07-26-2011
I'm using Debian Squeeze, and I use Bash.
Sorry for not specifying that, is there anything else I need to provide?
# 4  
Old 07-26-2011
BASH can modify it with the TIMEFORMAT variable, but unfortunately can't modify it very much. Time is only in seconds.
# 5  
Old 07-26-2011
For the first part (sum user and system time) you could use something like this (the result will be in seconds, not in milliseconds):

Code:
mytime() {
  { 
    command time -f '-- %U %S %e' "$@" 2>&1 >&3 |
      awk '/^--/ {
	      printf "%f(sys+usr) %f(real)\n", $2 + $3, $4 
        }' >&2
     } 3>&1
  }


For example:

Code:
% mytime ls -R /usr >/dev/null
1.150000(sys+usr) 1.190000(real)


Last edited by radoulov; 07-26-2011 at 05:46 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

How to Understand the UNIX Time Format?

How to understand the unix time format as here i have pasted this is a unix time 1402565420 and its 3:00 PM here but its give this Output as long number How can i make it to understand format as i have 3:00 PM Normal time format <----3:00PM = 1402565420----> Unix Time Will Any one Explain to... (4 Replies)
Discussion started by: babinlonston
4 Replies

2. Shell Programming and Scripting

Change the date and time format in UNIX script.

Hi, I am extracting a date string from the source file like this : 06/05/2014 16:04:00 I want to change it to 05-JUN-14 04.05.00.000000000 PM I basically store the date in a variable. I got solutions to change date in dd-mmm-yyyy format using tr but I guess it works only with the "date"... (8 Replies)
Discussion started by: Varshha
8 Replies

3. UNIX for Dummies Questions & Answers

UNIX command output format

how can I get the df -h command output into excel format or csv file. df -k | tr -s " " | sed 's/ /, /g' | sed '1 s/, / /g' | column -t df -h | column -t I have tried as above but the format is not right. I'm not able to load the format into a excel or a table. ... (2 Replies)
Discussion started by: anita81
2 Replies

4. Shell Programming and Scripting

Command for changing date format in a file

Hi... I have an inputfile name as :- abc_test_20120213.dat (date in yyyymmdd format) I need the output file name as abc_test_13022012.dat (date in ddmmyyyy format) Please help me on this... Thanks in advance. (5 Replies)
Discussion started by: gani_85
5 Replies

5. Shell Programming and Scripting

Help: transform unix time format to standard

Hello All, Do you have any idea, how can I transform the unix time format to standard: time_last_login=1268057983 :confused: I would like to use the transformation in a AIX shell script :( (6 Replies)
Discussion started by: kalaso
6 Replies

6. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

7. Shell Programming and Scripting

changing month in Mmm format to mm FORMAT

i have an variable mydate=2008Nov07 i want o/p as in variable mymonth=11 (i.e nov comes on 11 number month) i want some command to do this for any month without using any loop. plz help me (1 Reply)
Discussion started by: RahulJoshi
1 Replies

8. UNIX for Dummies Questions & Answers

changing the format of date in unix

When i execute the below command it is giving the timestamp in the format mentioned below ls -ltr 1234.txt | awk 'BEGIN {FS=" "} {print $6" "$7" "$8}' Mar 20 00:12 i want output in the format 200803200012 please help me how to do it here year is not returned and i have to convert mar to... (5 Replies)
Discussion started by: trichyselva
5 Replies

9. Windows & DOS: Issues & Discussions

conversion of unix time format

help me to convert unix time format into windows time format using java i have linux time ex. 1075329297.572 (2 Replies)
Discussion started by: sari
2 Replies

10. UNIX for Dummies Questions & Answers

Changing the UNIX command prompt

I am having a hard time figuring out how to change the command prompt in my UNIX shell. I am using the bash shell, and I would like to set the prompt to show me the full path of the current working directory along with my username, I suppose... The main thing I want is the full path of the... (2 Replies)
Discussion started by: WERUreo
2 Replies
Login or Register to Ask a Question