From: Michael French <mfrench@ashevillemail.com>
To: linux-admin@vger.kernel.org
Subject: Stupid programming question
Date: Wed, 19 May 2004 12:06:18 -0500 [thread overview]
Message-ID: <40AB940A.3080601@ashevillemail.com> (raw)
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
next reply other threads:[~2004-05-19 17:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-19 17:06 Michael French [this message]
2004-05-19 22:03 ` Stupid programming question Russell Evans
-- strict thread matches above, loose matches on Subject: below --
2004-05-19 17:22 JULIAN, JOHN C (AIT)
2004-05-19 16:45 ` A. R. Vener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40AB940A.3080601@ashevillemail.com \
--to=mfrench@ashevillemail.com \
--cc=linux-admin@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).