bc


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers bc
# 1  
Old 05-01-2008
bc

i have a filename contain:

123
1234
12345

i can use bc 123+1234+12345 = 13702, but can i use while loop ?

cat filename | while read line
do
not sure in this statement ?

done
# 2  
Old 05-01-2008
never mind, i can use this from this helpful site.

echo `sed -e 's/$/+/' myFile.txt` 0 | bc
# 3  
Old 05-01-2008
one draw back about this syntax is, i can not use it when the content of the file (# of lines in the file) more than 500 lines, it created core dump.

split -l 500 myFile.txt and use this output one at the time, work fine.

is it away to not split the file to do this ?
# 4  
Old 05-01-2008
Code:
nawk '{s+=$0} END {print s}' filename

# 5  
Old 05-01-2008
thanks, that works well. i am very new to scripting or commands such sed, awk, nawk, grep. so far, this site is pushing pass my bed time. people who are member of this site are ROCK!
 
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question