Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 7th, 2005, 10:54 PM   #1
vivaspeed
Newbie
 
Join Date: Jan 2005
Posts: 2
Rep Power: 0 vivaspeed is on a distinguished road
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
vivaspeed is offline   Reply With Quote
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
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC