User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 397,800 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,394 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 1423 | Replies: 3
Reply
Join Date: Jul 2006
Posts: 9
Reputation: nihao is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nihao nihao is offline Offline
Newbie Poster

Question About "diff -y"

  #1  
Jul 12th, 2006
Hello all:

I want to compare two folders by script like this "diff -yr folder1 folder2",but I find there are two problems in the result which is not what I want,please help me.

Problem One:
If there are two line is different,and every line is too long, the result will be shown like this "lineA ........... | lineB .........." ,in this case,every line will not be integrated.

Problem Two:
Because of using the parameter "-r",when the command "diff" get more than one different lines,some script in the right part of the line will be shown in the result,for example "lineA | lineBdiff -yr folder1/file33 folder2/file44".

How can I improve it?Please help me,thanks!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2004
Posts: 177
Reputation: jim mcnamara is on a distinguished road 
Rep Power: 5
Solved Threads: 9
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: About "diff -y"

  #2  
Jul 12th, 2006
First off:
-y produces side by side output. diff tries to fit two lines into 80 columns, that's why the lines are truncated.

-r displays a filename. otherwise you would never know what the diff output was based on.

what are you trying to do? && what output would you like to have?
Reply With Quote  
Join Date: Jul 2006
Posts: 9
Reputation: nihao is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nihao nihao is offline Offline
Newbie Poster

Re: About "diff -y"

  #3  
Jul 12th, 2006
Originally Posted by jim mcnamara
First off:
-y produces side by side output. diff tries to fit two lines into 80 columns, that's why the lines are truncated.

-r displays a filename. otherwise you would never know what the diff output was based on.

what are you trying to do? && what output would you like to have?

Hi jim mcnamara,thank you for your reply!
In fact,I need a shell script that output a result of the difference with a friendly format.So I hope the result will be shown normally when the two lines are longer than 80 columns.In addition,I want to convert this output "lineA | lineBdiff -yr folder1/file33 folder2/file44" into this output "lineA | lineB" + \n + "diff -yr folder1/file33 folder2/file44".And,in this case, how to judge that "diff -yf folder1/file33 folder2/file44" is not belonged to "lineB" ?
Would you help me?
Last edited by nihao : Jul 12th, 2006 at 10:36 am.
Reply With Quote  
Join Date: May 2004
Posts: 177
Reputation: jim mcnamara is on a distinguished road 
Rep Power: 5
Solved Threads: 9
jim mcnamara jim mcnamara is offline Offline
Junior Poster

Re: About "diff -y"

  #4  
Jul 12th, 2006
One way is to write a short script that compares files with like names:
#/bin/ksh

export PATH1=/path/to/folder1
export PATH2=/path/to/folder2

find $PATH1 -name '*' | \
while read file
do 
	base="`basename "$file"`"
	if [[ `cmp "$file" "$PATH2/""$base" 2>&1 > /dev/null; echo $?` -eq 1 ]] ; then
		echo "$file" " " "$PATH2/""$base"
		diff "$file"  "$PATH2/""$base"
	fi
done > diff.log

All the " " are there in case filenames have spaces.
Last edited by jim mcnamara : Jul 12th, 2006 at 2:33 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 6:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC