-2

i have a time file like this

time.log

12:30
13:10
16:00

and i want to redirect this file in this way

output.log

12:31
12:32
12:33
12:34
12:35
12:36
12:37
12:38
12:39
12:40
12:41
13:10
13:11
13:12
13:13
13:14
13:15
13:16
13:17
13:18
13:19
13:20
16:00
16:01
16:02
16:03
16:04
16:05
16:06
16:07
16:08
16:09
16:10
Thor
  • 45,082
  • 11
  • 119
  • 130
  • 3
    welcome to SO... see https://stackoverflow.com/help/how-to-ask and https://stackoverflow.com/help/mcve.. for formatting help, see https://stackoverflow.com/editing-help – Sundeep Apr 27 '17 at 15:02
  • 1
    There's no obvious mapping from your input to your output. input 12:30 outputs 12:31-> 12:41 but input 13:10 output 13:10->13:20. Add some explanation and/or fix your example. – Ed Morton Apr 27 '17 at 15:31

2 Answers2

1

Here's one in awk:

$ awk '
{
    for(i=0;i<=10;i++) {
        c="date -d \"" $1 " " i " minute\" +\"%H:%M\""
        system(c)
        close(c)
    }
}' file
12:30
12:31
12:32
12:33
...

Here RIPs one In Pieces in bash that I wrote even I knew better than that. :D Please don't quote me on that one.

$ while IFS= read -r line; do for j in {0..10}; do k="$i $j minute"; date -d "$k" +"%H:%M" ; done ; done < file
12:30
12:31
12:32
12:33

Explained:

while IFS= read -r line                                   # thanks @Sundeep
# for i in $(cat foo)          # for good old times sake, # I stand corrected
do
    for j in {0..10}           # add 0 to 10 to the time
    do
        k="$i $j minute"       # form the string for date
        date -d "$k" +"%H:%M"  # magic
    done
done < file
James Brown
  • 36,089
  • 7
  • 43
  • 59
  • 2
    [use while loop to read file](http://mywiki.wooledge.org/BashFAQ/001) .... – Sundeep Apr 27 '17 at 15:11
  • 1
    [why-is-using-a-shell-loop-to-process-text-considered-bad-practice](https://unix.stackexchange.com/questions/169716/why-is-using-a-shell-loop-to-process-text-considered-bad-practice) – Ed Morton Apr 27 '17 at 15:28
  • 1
    Lol. I knew I should've done in awk but I just whipped something around `date` to get its arguments right. – James Brown Apr 27 '17 at 15:31
1

another awk without system calls

awk -F: '{for(i=0;i<=10;i++) 
             printf "%02d:%02d\n", ($1+int($2/60))%24, ($2++)%60}' file
karakfa
  • 66,216
  • 7
  • 41
  • 56