![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Jan 2005
Posts: 2
Rep Power: 0
![]() |
Hi expert,
There are ton of files and it may not easy to "compare" with anyother tool then diff with unix command line. Want a shell or ksh script very much to print out the files with two slice view and print out the cmp line Example diff files - test_1.txt and test_2.txt test_1.txt ========= 1 UUU / sadf / 2 TTT \ asf \ 3 AAA 4 BBB 5 CCC 6 1234 7 DDD 8 ABC 9 ADCR 10 OICTE test_2.txt ========= 1 FFF / RCff / 2 Tyyy \ XML \ 3 AAA 4 ZZZ 5 CCC 6 1234 7 GGG 8 ABC 9 ADCee 10 OICrr ===================== expected output: To ignore the different between line 1; 2; 9 and 10 test_1.txt test_2.txt ==========+================ UUU / sadf / | FFF / RCff / TTT \ asf \ | Tyyy \ XML \ AAA | AAA BBB | ZZZ CCC | CCC 1234 | 1234 DDD | GGG ABC | ABC ADCR | ADCee OICTE | OICrr Different: test_1.txt >> BBB test_2.txt << ZZZ test_1.txt >> DDD test_2.txt >> GGG condition ======= Found differents display Result = Fail No different found Result = OK ============================ Please advise. Thank you. Vivaspeed |
|
|
|
|
|
#2 | |
|
Newbie
Join Date: Feb 2005
Posts: 12
Rep Power: 0
![]() |
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`
doneThe above takes two files, aptly named foo1 and foo2, and with your data in it, gives the following: Quote:
__________________
--Vorlin "Systems administration - it's not just my job, it's how I buy video games!" |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|