#/usr/bin/gawk
function between(str, first, last){
  len=length(first)
  begin=index(str, first)+len
  end=index(str, last)
  return substr(str, begin, end-begin)
}
/hierarhia/ {
  num=between($0, "center\">", "</td>")
#Some hackish stuff to fool awk. Without that it would add num as integer, not as string
  questions[num]="nr|"
  questions[num]=questions[num] num
}
/triip/ {
  question="|"between($0, "triip\">","</td>")
  questions[num]=questions[num] question
}
/color:#CC0000/ {
  selected="|-|"between($0, "          >", "</td>")
  questions[num]=questions[num] selected
}
/<td           >/ {
  unselected="|+|"between($0, "<td           >", "</td>")
  questions[num]=questions[num] unselected
}
/img src=/ {
  img="|img|" between($0, "img src=\"","jpg\" width") "jpg"
  questions[num]=questions[num] img
}
END{

  for (question in questions){
          #print questions[question]
  }
  n=asorti(questions, sorted)
  for (i=1;i<=n;i++){
          print sorted[i]
  }
}