[%] awk '{count=ind=1;chapters[ind]=$1;for(i=2;i<=NF;i++){if($i>$count){chapters[ind]=chapters[ind]" "$i}else{chapters[++ind]=$i}count++}for(chapter in chapters)printf"Chapter%d: %s\n",chapter,chapters[chapter]}' <<< "30 33.993 76.123 0.6 43.234 87.234 130.345" Chapter1: 30 33.993 76.123 Chapter2: 0.6 43.234 87.234 130.345