From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael French Subject: Stupid programming question Date: Wed, 19 May 2004 12:06:18 -0500 Sender: linux-admin-owner@vger.kernel.org Message-ID: <40AB940A.3080601@ashevillemail.com> Reply-To: mfrench@ashevillemail.com Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: List-Id: Content-Type: text/plain; charset="us-ascii"; format="flowed" To: linux-admin@vger.kernel.org I have two text files each with a single column of numbers in them and I want to write a script that multiplies the number on each line of file one with the corresponding number from file two and produces a sum of the multiplied numbers in the 2 files.. How would I do this with a loop? This is just a small shell script, I can use perl if I need to, I just need to know the data structure. If it was just one file, I would do something like this: SUM=0 NUMBER1=`cat $FILE1` for m in $NUMBER1 do SUM=`echo "scale=4; $SUM * $m" |bc` done Not exactly right, but you get the jist of it. Obviously this won't work: SUM=0 NUMBER1=`cat $FILE1` NUMBER2=`cat $FILE2` for m in $NUMBER1 and n in $NUMBER2 do SUM=`echo "scale=4; $m * $n" |bc` done Thanks for any help you can provide, let me know if you need more info. Michael French