LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   more script (https://www.linuxquestions.org/questions/programming-9/more-script-1235/)

rand07 03-09-2001 11:01 AM

If I have a list of numbers in a file, how do I add the numbers together? Do I use grep???

crabboy 03-09-2001 09:19 PM

grep will not do you any good. grep can only find text in files based on a search criteria.

This script will work.

#!/bin/sh

TOTAL=0

for NUM in `cat filename`; do
TOTAL=`expr $NUM + $TOTAL`
done

echo $TOTAL


All times are GMT -5. The time now is 08:22 PM.