#!/bin/bash height=`identify $2 | egrep -o [0-9]+x[0-9]+ | egrep -o '[0-9]+$'` temp=$3 convert $2 $temp old=$IFS IFS=$'\n' for line in $( cat "$1" ) do count="0" IFS=$old for num in $( echo $line | egrep -o '[0-9]{2,5}' ) do count=$(($count + 1)) case "$count" in 1) ax="$num" ;; 2) ay=$(($height - $num)) ;; 3) bx="$num" ;; 4) by=$(($height - $num)) ;; *) echo "hmmmm:$count:$num" ;; esac done convert $temp -stroke red -strokewidth 1 -draw "line $ax,$ay $bx,$ay" $temp convert $temp -stroke red -strokewidth 1 -draw "line $ax,$ay $ax,$by" $temp convert $temp -stroke red -strokewidth 1 -draw "line $bx,$by $bx,$ay" $temp convert $temp -stroke red -strokewidth 1 -draw "line $bx,$by $ax,$by" $temp IFS=$'\n' done IFS=$old