#!/bin/bash make_group_chapters() { unset index i tmp input=( "$@" ) chapters=() index=1 chapters[$index]=${input[$((index-1))]} for ((i=1;i<${#input[@]};i++)); do tmp="${chapters[$index]##* }" if (( ${input[$i]%.*} > "${tmp%.*}" )); then chapters[$index]="${chapters[$index]} ${input[$i]}" else ((index++)) chapters[$index]="${input[$i]}" fi done for c in ${!chapters[@]}; do chapter_array[x++]="${chapters[c]}" done } function format_seconds() { awk '{ hr=($1/3600); hd=(sprintf("%02d", hr)) mr=((hr-hd)*60); md=(sprintf("%02d", mr)) s=((mr-md)*60); sd=(sprintf("%02d", s)) t=(sprintf("%02d:%02d:%06.3f" ,hd,md,s)); print t}' <<< $1 } make_group_chapters "$@" for index in "${!chapter_array[@]}"; do for number in ${chapter_array[index]}; do new_element="$new_element $(format_seconds $number)" done array[index]="$new_element" unset new_element done for i in ${!array[@]}; do echo "${array[i]}" done ################################ output ############################### $ sh work_on_numbers 30.345 52.234 66.32 12.34 42.52 73.34 26.34 4.34 60.34 00:00:30.345 00:00:52.234 00:01:06.320 00:00:12.340 00:00:42.520 00:01:13.340 00:00:26.340 00:00:04.340 00:01:00.340