Counting time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Counting time
# 1  
Old 12-10-2001
Counting time

I have been wrestling with a ksh module to calculate a series of elapes times in the format hh:mm:ss. I have use the 'cut' command to extract the seconds and minutes and added the results together and then divided by 60 to yield a result, then added the result to the next field, but this seems to be a rather primative way of handling the situation. Are there any suggestions that may provide a better way?

Thanks in advance
# 2  
Old 12-10-2001
Hey black69star,
Check out the "timex" command. I don't know the structure of your script, but this may help you. Basically, you just run your command like normal but type timex infront of it. It then returns several bits of info that you can chop up, etc to get the time. This may or may not work for you.
Good Luck,
TioTony
# 3  
Old 12-11-2001
I'm not sure what you're trying to do exactly. But if you have a string like "18:30:10" and you want to convert it to seconds after midnight, try:
Code:
#! /usr/bin/ksh
hms="18:30:10"
h=${hms%%:*}
s=${hms##*:}
temp=${hms%:*}
m=${temp#*:}
((secs=3600*h + 60*m +s))
echo $hms $h $m $s $secs
exit 0

By using only shell built-ins like this you can run must faster than if you invoke external processes like "cut".

Also, this thread may be of some help.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

2. UNIX for Dummies Questions & Answers

counting?

Hi all, I promise this is my very last dumb question.. but how to you count how many unique names you have. My dataset is: >Bac1 afdsgrr >Bac4 egege >Bac8 dgrjh >Bac1 afdsgrr >Bac1 afdsgrr >Bac8 dgrjh What i want to know is that how many unique names there is, so the output would... (3 Replies)
Discussion started by: Iifa
3 Replies

3. UNIX for Dummies Questions & Answers

Counting # of lines

Counting number of lines: sp I am trying to figure out a script to count the number of text files in cywig and have it give me a number (as the answer) any help would be appreciated. I am new here, so be gentle :D (3 Replies)
Discussion started by: unicksjp
3 Replies

4. Shell Programming and Scripting

counting word xx referred to a time period, like minute or hour

Hello, I try to insert a post because I've got a trouble to perform a unix job. But I didn't found which steps (procedure) I should follow. Could you help me? I got a log by my Application box, like following: gbosmam037:test >view Log_Server.csv ... (2 Replies)
Discussion started by: maluca68
2 Replies

5. Shell Programming and Scripting

Counting

Hi, The following output shows how many pmon process are started by users named : oracle or yoavb $ ps -ef |grep pmon |grep -v grep |grep -v ipmon oracle 11268 1 0 Sep 2 ? 36:00 ora_pmon_qerp oracle 17496 1 0 Oct 11 ? 8:58 ora_pmon_bcv oracle 15081 1 0 ... (5 Replies)
Discussion started by: yoavbe
5 Replies

6. Shell Programming and Scripting

Counting

Hi, I want to count how many rows are in a file for a specific column. eg. K NM K NM K NM K JK K NM K JK K NM so the file is tab-delimited. I want to count how many rows are in column 2 and how many NMs there are. I used awk awk '{OFS="\t"}; {count++} {print i,... (3 Replies)
Discussion started by: phil_heath
3 Replies

7. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

8. Shell Programming and Scripting

Counting up a variable

Hello, I am trying to write a shell script, but i encountered a problem I cant solve alone so I hope you guys can help me. The situation is: I have a script file and a config file, in my config file I set some Variables: for example: destination=(xp, xq, xt) username=testor... (3 Replies)
Discussion started by: Kenada
3 Replies

9. UNIX for Advanced & Expert Users

How To Provide Time Sync Using Nts-150 Time Server On Unix Network?

can anybody tel lme,how to instal NTS -150 on a unix network,it needs some patch to fetch time frm serve,,?? (2 Replies)
Discussion started by: pesty
2 Replies
Login or Register to Ask a Question