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!

Recommended Answers

All 3 Replies

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?

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.