View Single Post
Old Feb 27th, 2005, 7:49 PM   #2
Vorlin
Newbie
 
Join Date: Feb 2005
Posts: 12
Rep Power: 0 Vorlin is on a distinguished road
I think I have the understanding that you're trying to not display the differences between the two files and if that's the case, I think I might've gotten it.

#!/bin/sh

# Set up the variables here, length and whatnot
FILE1="$HOME/foo1"
FILE2="$HOME/foo2"
DIFF_FILE="$HOME/diff_file"
FILE1_LEN=`wc -l $FILE1 | awk '{ print $1 }'`
FILE2_LEN=`wc -l $FILE2 | awk '{ print $1 }'`

if [ $FILE1_LEN < $FILE2_LEN ]; then
        TOTAL_LINES=$FILE1_LEN
elif [ $FILE1_LEN > $FILE2_LEN ]; then
        TOTAL_LINES=$FILE2_LEN
fi

DIFF_RUN=`diff --side-by-side $FILE1 $FILE2 | grep \| > $DIFF_FILE`
DIFF_RESULTS=`cat diff_file | awk '{ if ($1 != "<" && $1 != ">" && $1 != "---") { print $1 } else if ($1 == ">" || $1 == "<") { print $3 " " $4 " " $5 ", "}}'`

NUM=1
until [ $NUM -gt $TOTAL_LINES ];
do
        echo -n "Checking line #$NUM :: "
        CHECK=`grep "^$NUM" $DIFF_FILE | sed -e 's/[|]/||/'`
        echo $CHECK
        NUM=`expr $NUM + 1`
done

The above takes two files, aptly named foo1 and foo2, and with your data in it, gives the following:

Quote:
Checking line #1 :: 1 UUU / sadf / || 1 FFF / RCff / 10 OICTE || 10 OICrr
Checking line #2 :: 2 TTT \ asf \ || 2 Tyyy \ XML \
Checking line #3 ::
Checking line #4 :: 4 BBB || 4 ZZZ
Checking line #5 ::
Checking line #6 ::
Checking line #7 :: 7 DDD || 7 GGG
Checking line #8 ::
Checking line #9 :: 9 ADCR || 9 ADCee
Checking line #10 :: 10 OICTE || 10 OICrr
Little bit easier to read than diff, but still comes out a bit off...the double || serve as an indication that the next difference is being shown.
__________________
--Vorlin

"Systems administration - it's not just my job, it's how I buy video games!"
Vorlin is offline   Reply With Quote