help with command syntax for bc (binary calculator) - Questions

This is a discussion on help with command syntax for bc (binary calculator) - Questions ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: help with command syntax for bc (binary calculator)

  1. help with command syntax for bc (binary calculator)

    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


  2. Re: help with command syntax for bc (binary calculator)

    Don't know about bc, but try using awk?
    cat inputfile | awk '{print ($1*0.123/0.321)+13) } ' > output


  3. Re: help with command syntax for bc (binary calculator)

    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.


  4. Re: help with command syntax for bc (binary calculator)

    In article , mitch wrote:
    > 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


    (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 =----

+ Reply to Thread