All pastes #280839 Raw Edit

Unnamed

public text v1 · immutable
#280839 ·published 2006-12-16 05:35 UTC
rendered paste body
#!/bin/bash

GROUP_CHAPTERS=("30 33.993 76.123 0.6 43.234 87.234 130.345" "30 55.22 120.344 300.233 34.25 66.3")

script='
{
   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)
      print chapters[chapter]
}'
for i in ${!GROUP_CHAPTERS[@]}; do
    while read foo; do array[x++]=$foo; done <<<  "$(awk "$script" <<< "${GROUP_CHAPTERS[i]}")"
done
for c in ${!array[@]}; do
    echo array[$c] is ${array[c]}
done

#### output ####
$ sh awk_chapters
array[0] is 30 33.993 76.123
array[1] is 0.6 43.234 87.234 130.345
array[2] is 30 55.22 120.344 300.233
array[3] is 34.25 66.3