#!/bin/sh # parse query test "$QUERY_STRING" || QUERY_STRING="$1" book=$(echo $QUERY_STRING|cut -d' ' -f1) chstart=$(echo $QUERY_STRING|tr ':' ' ' |cut -d' ' -f2) vstart=$(echo $QUERY_STRING|tr '-' ':' | cut -d: -f2) # vend is always the last number vend=$(echo $QUERY_STRING |tr - : |rev|cut -d: -f1|rev) # chend is the last leftover chend=$(echo $QUERY_STRING|sed "s/$book //"| sed "s/:$vstart-/ /"|sed "s/ \?:\?$vend$//"|rev|cut -d' ' -f1|rev) #echo $chstart "\t" $vstart "\t" $chend "\t"$vend && exit file=$(find oeb/ -name '*'-$book'*') grep '\c '$chstart $file -A500 | grep '\v '$vstart -A500 \ | grep '\c '$(($chend + 1)) -B500 | grep '\v '$vend -B500