Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

help with command syntax for bc (binary calculator)

3 views
Skip to first unread message

mitch

unread,
Mar 15, 2005, 2:27:46 PM3/15/05
to
I would like to pipe a file of numbers (one per line) to "bc" and have it run a function
like :
(( $input * 0.123 / 0.321 ) + 13 )

and spit all that back out to another file, can anyone help me with that syntax, I
want to do something like (I know this wont't work)

cat inputfilename | bc (( $input * 0.123 / 0.321 ) + 13 ) > outputfilename


thnx


regards,
Mitch

Vfrc

unread,
Mar 15, 2005, 3:12:03 PM3/15/05
to
Don't know about bc, but try using awk?
cat inputfile | awk '{print ($1*0.123/0.321)+13) } ' > output

Vfrc

unread,
Mar 15, 2005, 3:16:06 PM3/15/05
to
Ahem, the left bracket in my post needs to be doubled of course, to
read:
cat inputfile | awk '{print (($1*0.123/0.321)+13) } ' > output
Sorry about that.

Larry Starr

unread,
Mar 18, 2005, 11:46:34 PM3/18/05
to

(sed -e 's/^.*$/a += &/' ifile; echo '((a * 0.123 / 0.321 ) + 13 )') | \
bc > ofile
or
sed -e 's/^.*$/((& * 0.123 \/ 0.321 ) + 13 )/' inputfilename | \
bc > outputfilename

Depending on if you want to do the calculation on the sum of the lines
in the input file or on each line in the file.

Only guessing on the format of your input, of course.

Also you may want to specify precision:
(echo 'scale=3; sed -e 's/^.*$/((& * 0.123 / 0.321 ) + 13 )/' ifile) | \
bc > ofile


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

0 new messages