#!/bin/bash unset A1 A2 A3 A4 A5 A6 A7 A8 A9 unset B1 B2 B3 B4 B5 B6 B7 B8 B9 read B1 B2 B3 B4 B5 B6 B7 B8 B9 while [ -n "${B1}" ]; do DIFFS="0" unset LASTDIFF if [ "${A1}" != "${B1}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="1" ; fi if [ "${A2}" != "${B2}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="2" ; fi if [ "${A3}" != "${B3}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="3" ; fi if [ "${A4}" != "${B4}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="4" ; fi if [ "${A5}" != "${B5}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="5" ; fi if [ "${A6}" != "${B6}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="6" ; fi if [ "${A7}" != "${B7}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="7" ; fi if [ "${A8}" != "${B8}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="8" ; fi if [ "${A9}" != "${B9}" ]; then DIFFS=$[ ${DIFFS} + 1 ] ; LASTDIFF="9" ; fi if [ "${AISREAL}" = "yes" ]; then case ${DIFFS} in 0) #Don't do anything; the lines are identical, so drop one (A) ;; 1) # Figure out differences here. Once a replacement for the sole delta field is entered, # line A can be dropped and B can come around again to be compared to the next line. case ${LASTDIFF} in 1) AVER=${A1} ; BVER=${B1} ;; 2) AVER=${A2} ; BVER=${B2} ;; 3) AVER=${A3} ; BVER=${B3} ;; 4) AVER=${A4} ; BVER=${B4} ;; 5) AVER=${A5} ; BVER=${B5} ;; 6) AVER=${A6} ; BVER=${B6} ;; 7) AVER=${A7} ; BVER=${B7} ;; 8) AVER=${A8} ; BVER=${B8} ;; 9) AVER=${A9} ; BVER=${B9} ;; esac clear echo The following lines differ only in field ${LASTDIFF}. echo ${A1} ${A2} ${A3} ${A4} ${A5} ${A6} ${A7} ${A8} ${A9} echo ${B1} ${B2} ${B3} ${B4} ${B5} ${B6} ${B7} ${B8} ${B9} echo Please enter a suitable replacement for \"${AVER}\" and \"${BVER}\", or echo just press enter to keep \"${BVER}\". unset NEWVER JUNK read NEWVER JUNK if [ -z "${NEWVER}" ]; then NEWVER=${BVER} fi case ${LASTDIFF} in 1) B1=${NEWVER} ;; 2) B2=${NEWVER} ;; 3) B3=${NEWVER} ;; 4) B4=${NEWVER} ;; 5) B5=${NEWVER} ;; 6) B6=${NEWVER} ;; 7) B7=${NEWVER} ;; 8) B8=${NEWVER} ;; 9) B9=${NEWVER} ;; esac echo The merged line is: echo ${B1} ${B2} ${B3} ${B4} ${B5} ${B6} ${B7} ${B8} ${B9} ;; *) # The lines have more than one field difference. Just output. echo ${A1} ${A2} ${A3} ${A4} ${A5} ${A6} ${A7} ${A8} ${A9} ;; esac fi A1=${B1} ; A2=${B2} ; A3=${B3} ; A4=${B4} ; A5=${B5} ; A6=${B6} ; A7=${B7} ; A8=${B8} ; A9=${B9} AISREAL="yes" LASTLINE="${B1} ${B2} ${B3} ${B4} ${B5} ${B6} ${B7} ${B8} ${B9}" unset B1 B2 B3 B4 B5 B6 B7 B8 B9 read B1 B2 B3 B4 B5 B6 B7 B8 B9 done echo ${LASTLINE}