#!/bin/bash make_chapters() { 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 printf "${chapters[1]}\n${chapters[2]}\n" } make_chapters "$@" #Example: #[%] ./script 30 33.993 76.123 0.6 43.234 87.234 130.345 #30 33.993 76.123 #0.6 43.234 87.234 130.345