Hi Folks,
I have the following primitive shell script, which works cool, except its freak'n slow.
Can anyone suggest some tips to speed it up ?
... I suspect it's the the way I'm invoking expr, I have a funny feeling that's spawning a new command shell to execute.
I tried changing one like to:
pages=$(echo "( $lineCount / 12 ) + 1" | bc)
... but it didnt help much. Any other ideas ?
I have the following primitive shell script, which works cool, except its freak'n slow.
Can anyone suggest some tips to speed it up ?
Code:
#!/bin/ksh
dataFile=$1
sourcePDFFile=$2
pdfOffset=0
while read line; do
startTag=`echo $line | grep -c "<DESPATCH>"`
if [[ $startTag -eq 1 ]]; then
lineCount=0
fi
docTag=`echo $line | grep -c "<DESPNO>"`
if [[ $docTag -eq 1 ]]; then
docId=`echo $line | cut -f2 -d'>' | cut -f1 -d'<'`
fi
lineTag=`echo $line | grep -c "<INVLINE>"`
if [[ $lineTag -eq 1 ]]; then
let lineCount+=1
fi
endTag=`echo $line | grep -c "</DESPATCH>"`
if [[ $endTag -eq 1 ]]; then
pages=`expr \( $lineCount / 12 \) + 1`
pdfOffset=`expr $pdfOffset + $pages`
docLast=`expr $pdfOffset + $pages`
echo "Document: $docId Has: $pages pages for: $lineCount lines"
/usr/sfw/bin/gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage=${pdfOffset} -dLastPage=${docLast} -sOutputFile=${docId}.pdf ${sourcePDFFile}
fi
done < $dataFile
... I suspect it's the the way I'm invoking expr, I have a funny feeling that's spawning a new command shell to execute.
I tried changing one like to:
pages=$(echo "( $lineCount / 12 ) + 1" | bc)
... but it didnt help much. Any other ideas ?