Round up time to 5min


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Round up time to 5min
# 1  
Old 02-13-2012
Round up time to 5min

Hi,
I have a data like
Code:
Date Time Pulse
04/02/2012 00:01:05 2
04/02/2012 00:01:48 5
04/02/2012 00:02:09 3
04/02/2012 00:03:19 4
04/02/2012 00:04:40 1
04/02/2012 00:04:45 9
04/02/2012 00:05:15 15
04/02/2012 00:05:48 9
04/02/2012 00:06:49 12
04/02/2012 00:07:00 19
04/02/2012 00:07:45 1
04/02/2012 00:08:40 4
04/02/2012 00:09:10 5
04/02/2012 00:10:00 7
04/02/2012 00:10:47 10
.
.
.
.
.
.
05/02/2012 00:02:47 10
05/02/2012 00:03:35 10
.
.
.

My concern is, I need ouput like-
Code:
Date_Time
04/02/2012_00:00
04/02/2012 00:00
04/02/2012 00:00
04/02/2012 00:00
04/02/2012 00:00
04/02/2012 00:00
04/02/2012 00:05
04/02/2012 00:05
04/02/2012 00:05
04/02/2012 00:05
04/02/2012 00:05
04/02/2012 00:05
04/02/2012 00:05
04/02/2012 00:10
04/02/2012 00:10
.
.
05/02/2012 00:00
05/02/2012 00:00
.
.
.

Means I need to round up time 00:01:00 to 00:04:59 as 00:00,
00:05:00 to 00:09:59 as 00:05 and so on.

Thanks in advance.


Moderator's Comments:
Mod Comment Please use code tags!
for your code and data!

Last edited by vbe; 02-13-2012 at 12:40 PM..
# 2  
Old 02-13-2012
convert the time to seconds, add 300, divide by 300, discard remainder, multiply by 300 and convert back to hours minutes.
Code:
seconds = hours * 3600 + minutes * 60 + seconds + 300
seconds = int(seconds/300)
seconds = seconds *300
hours= mod(seconds,3600)
minutes =mod (seconds - hour * 3600,60)
seconds = 0

# 3  
Old 02-15-2012
Thanks for your reply.
But its not working in my case as its not in proper format. However I have separate out min values and now trying to round off them to nearest multiple of 5.
So now data at my side is:
07
15
21
03
47
36
08
12
20
.
.
.
And so on.
And my required output is:
10
15
25
05
50
40
10
15
20
.
.
.
.
And so on.
But I am not able to round off it to nearest multiple of 5. Please reply.
# 4  
Old 02-15-2012
Try divide and multiply.
shell:
Code:
v=37
printf "%02d\n" "$(( (v+2)/5*5 ))"


Last edited by Scrutinizer; 02-15-2012 at 05:18 AM..
# 5  
Old 02-15-2012
As per the initial given example :

Code:
awk -F"[ :]" 'NR==1{print $1"_"$2;next}{printf "%s%02d\n",$1" "$2 ":",5*int($3/5)}' OFS=":" yourfile

If second example , then the right formula should be :

Code:
5*int(($3+2.5)/5)

Code:
$ awk 'BEGIN{x=42.4;y=42.5;print 5*int((x+2.5)/5)" - "5*int((y+2.5)/5)}'
40 - 45

But since there is no decimal value so far, Scrutinizer formula also works fine.

Last edited by ctsgnb; 02-15-2012 at 05:27 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using awk to Summarize Log File in 5min Intervals

I have huge log file that taken every minute and I need the total at 5min intervals. Sample log: #timestamp(yyyymmddhhmm);result;transaction 201703280000;120;6 201703280001;120;3 201703280002;105;3 201703280003;105;5 201703280004;105;5 201703280005;105;4 201703280006;120;2... (2 Replies)
Discussion started by: wwolfking
2 Replies

2. Shell Programming and Scripting

Round up the decimals

Hi All, I would like to do the following in the shell script 561.76 to 562 I tried using this echo 'scale=0; 749 * 75 /100 ' | bc but just returned only 561 Please help me . I appreciate your help Thanks rajeevm (13 Replies)
Discussion started by: rajeevm
13 Replies

3. Shell Programming and Scripting

How to round up on fives in unix?

i'm a newbie here, i need help with a shell script. for a given number, if it is greater than ten round to the nearest 10 same for 100, if it is greater than 100 round to the nearest 100, and same for 1000. i'm confused how to start this... its supposed to look like this input ... (11 Replies)
Discussion started by: CRAZYLITTLELOU
11 Replies

4. Shell Programming and Scripting

Round off the a Decimal value.

HI, I have a script which is used to calculate the Memory & CPU utilization a server. memx=`ssh -l siebel1 ${f} /usr/sbin/prtconf|grep -i 'Memory size'|tr -s " "|/usr/xpg4/bin/awk -F" " '{print $3 * 1024}'` v5=`ssh -l siebel1 ${f} vmstat 1 2 | tail -1 | tr -s " " | /usr/xpg4/bin/awk -v... (3 Replies)
Discussion started by: dear_abhi2007
3 Replies

5. HP-UX

Location Of SAM 5min Shutdown Warning

Posted this question in another segment by error, but here goes. Lost my notes on the location of the 5min shutdown warning when using SAM. I set my single user system to 0mins so I don't have to keep backspacing out the 5mins and changing it to 0mins. Thanks (Located my old notes by accident,... (4 Replies)
Discussion started by: MINICooperS
4 Replies

6. Shell Programming and Scripting

Round with awk

Hi, I have a problem. Basically I dont know how to use awk. I have a script (below) which works fine. What I want to do is somehow "pipe" in the input say 4.5 and have it give the anwer, I dont want ot have to type it in, since it will be running in a script. Any ideas how to do this???? ... (1 Reply)
Discussion started by: AnnaLynn
1 Replies

7. Shell Programming and Scripting

Round the column value :

Hi .... Iam having the file ....in which 3rd column is numerical having 8 decimal part... i want that to cut to 2 decimal part ... Source File : E100|0|19940.10104030|0|1ABC E103|1|19942.10195849|3|0ABC E100|0|19943.10284858|0|1ABC I want to be ...... Reulst: ... (4 Replies)
Discussion started by: satyam_sat
4 Replies

8. Shell Programming and Scripting

round a number

In a shell script - How do I round a decimal number (contained in a variable) to the nearest whole number? (2 Replies)
Discussion started by: achieve
2 Replies

9. Shell Programming and Scripting

round in KSH

Is there an easy way to round a number up in Korn shell? ie. 10.4 --> 11 Thanks. (6 Replies)
Discussion started by: here2learn
6 Replies

10. UNIX for Dummies Questions & Answers

how to round a value

Hello, In a unix shell script,i want to round a variabele to a nearest number Ex: set count=104.4 How can i round that to 105.? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies
Login or Register to Ask a Question