Stupid programming question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
-
: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Newbie]     [Audio]     [Hams]     [Kernel Newbies]     [Util Linux NG]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Device Drivers]     [Samba]     [Video 4 Linux]     [Git]     [Fedora Users]

  Powered by Linux