Hi all,

I wrote a simple script to compute a difference between two
numbers extracted from a text file. It works fine but
performance is not that great. I wonder how to speed up
this script but it goes beyond my current Bash knowledge.
I know that there is a lot of redundancy on my code but
when I first wrote it speed was not much of a concern...

In short, open one file at a time, recognize and grab two numbers
using some pattern, take the difference between them and output to a file.

I really appreciate any help,

S.

Obs. I know that I could have used Perl, C, etc but I want to
learn how to write a more polished shell script.

-----------------------------------------------------------------------------
#
# Input files are named FILE.X, where X runs from 1 to 5000.
#
first=1
last=5000
loop=$first
#
while [ $loop -le $last ]
do
#
# Grab numbers from file FILE.X using filters
#
list1=(`grep "Pattern1" FILE.$loop | awk '{print $3}'`)
list2=(`grep "Pattern2" FILE.$loop | awk '{print $4}'`)
#
# Execute Math (each list has 15000 elements. Compute the
# difference between the lists and
# save the result to a file)
#
i=0
while [ $i -le 14499 ]
do
a=${list1[$i]}
b=${list2[$i]}
c=$(echo "scale=3; $a - $b" | bc)
echo $c > induce.$loop
i=`expr $i + 1`
done
loop=`expr $loop + 1`
done