#!/bin/sed -f # add.sed - add a list of decimal numbers (in domain 0-99999999) # Written by Greg Ubben on 15 March 1989 1{ h s/.*/jihgfedcba/ # initialize total in hold space to 00000000 x } H # append digital input number to analog total g :a s/9$/aaaaaaaaa/ s/8$/aaaaaaaa/ s/7$/aaaaaaa/ s/6$/aaaaaa/ s/5$/aaaaa/ # convert last digit to analog s/4$/aaaa/ s/3$/aaa/ s/2$/aa/ s/1$/a/ s/0$// s/\(aa*[^a]*\)\(a*\)/\2\1/ # combine with corr. totals place s/a\{11\}/ba/ # reduce (carry) if more than 10 y/jihgfedcba/ihgfedcbaj/ # rotate totals places for next digit /^j/!ba # loop 8 times, until "a" is back in units position s/.$// # delete the \n that was between the two numbers h # save total so next number can be read in $!d # if not EOF, loop to read in next number p s/\([a-z]\)\1\1\1\1\1\1\1\1\1/9/g s/\([a-z]\)\1\1\1\1\1\1\1\1/8/g s/\([a-z]\)\1\1\1\1\1\1\1/7/g s/\([a-z]\)\1\1\1\1\1\1/6/g s/\([a-z]\)\1\1\1\1\1/5/g s/\([a-z]\)\1\1\1\1/4/g # convert analog total to digits s/\([a-z]\)\1\1\1/3/g s/\([a-z]\)\1\1/2/g s/\([a-z]\)\1/1/g s/\([a-z]\)/0/g s/^0*\(.\)/\1/ # strip leading 0's