Question

I need to write a shell script that will create a list of 5 minutes interval times.

00-00
00-05
00-10
00-15
...
...
23-50
23-55

Here are the commands I have started with.

# date
Fri Sep 21 18:14:35 IST 2012

# date '+%H-%M'
18-14

# date '+%H-%M' --date='5 minute ago'
18-18

How do I write a script to generate the list? If it is too complicated, I will do it manually since it is one time task.


Update:

The following script is working. But it will generate single digits like 7-5 should actually be 07-05

#!/bin/sh
for hour in `seq 0 24`
do
for minute in `seq 0 5 59`
do
echo $hour-$minute
done
done
Was it helpful?

Solution 3

The following shell scripting is returning the required data

#!/bin/sh
for hour in `seq -w 0 24`
do
for minute in `seq -w 0 5 59`
do
echo $hour-$minute
done
done

OTHER TIPS

A simple bash solution (version 4 or later):

printf "%s\n" {00..23}-{00..55..5}

If you need to start at a given date, you can use:

ITERATIONS=100 # adjust here
D=$(date +%s)
for ((i=0; i<$ITERATIONS; i++))
do 
  date '+%H-%M' -d @$((D+5*60*i))
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top