Results 1 to 4 of 4

Thread: arithematic

  1. #1
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25

    Unanswered: arithematic

    I need a little help adding up some numbers.

    I have a file with the following 5 lines inside it:
    22
    356
    0
    121
    34

    I want to cat that file and add those numbers to get a total (533). The number of lines inside the file will be different each day. Any help would be greatly appreciated.

    Thanks,
    Jeff

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool


    If Numfile.txt is the file with the numbers, then do this:
    Code:
    awk '{t+=$1;} END {printf "Total=%s\n", t;}' NumFile.txt

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Apr 2004
    Location
    Winston-Salem, NC
    Posts
    25

    That worked!

    That's perfect, thanks a bunch!

  4. #4
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Code:
    echo `sed -e 's/$/+/' NumFile.txt` 0 | bc
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •