Quote:
Originally Posted by ryanlum
becuase there are times when the format is like this
1&1&&2&
|
Could this help? In bash...
lakris@Lakrix:~/Projects/scripts$ cat source.txt
1&1&1&1&1&3&1&1&1&1
1&2&2&2&2&3&2&1&1&1
1&2&7&2&2&3&2&1&1&1
1&2&2&2&2&3&2&1&1&1
1&2&9&2&2&3&2&1&1&1
1&2&&2&2&3&2&1&1&1
lakris@Lakrix:~/Projects/scripts$ val=0;sum=0;while read line;do val=`echo $line|cut -d"&" -f3`; [ x$val == x ] && val=0; sum=$(($sum+$val)); done < source.txt; echo $sum
21
lakris@Lakrix:~/Projects/scripts$
It reads the file, extracts the third &-separated field and accumulates it, and prints the sum.
/Lakris