Find with in loops and then difference

Hi All,

Please find my problem below:
I have a file at two different nodes dev and test

1st find> find /u/dev/local/abc -name ab.dat
--Since this file can be in several sub directories
2nd find> find /u/test/local/abc -name ab.dat

I find my 1st find result and do compare with 2nd find result. Have to see the diffrence in the two file.

I am doing a find on the following way since I have file ab.dat in many sub directories of /u/dev/local/abc (/u/dev/local/abc/p1,/u/dev/local/abc/p2/p01 etc). I need to search for prence of thsi file in each sub directory and then compare it with subsequent test file.

The above find gives me list of all the ab.dat file with their sub-directories. I do not want to use an external file to store the result and then pick one by one and do diff in dev and test directories. Is there way to do it through loops.:wall:

Find in dev --> get the first dev/d1/ab.dat then look for the corresponding test directory test/d1/ab.dat and then do diff ans say there was difference the go on to search next in loop and print the list of the path/ab.dat file having difference.

Thanks,
Varun

By "subsequent" do you mean corresponding?

1 Like

Do you need to compare each file with every other file, or just with the one found after it?

find /u/dev/local/abc -name ab.dat | while read LINE
do
        if [ ! -z "$PREV" ]
        then
                echo "Comparing $LINE with $PREV"
        fi

        PREV="$LINE"
done
1 Like

@Methyl/Corona688: Yes
1st find> find /u/dev/local/abc -name ab.dat
results:
/u/dev/local/abc/pqr/ab.dat
/u/dev/local/abc/pqr/xyz/ab.dat
/u/dev/local/abc/mno/ab.dat
2nd find> find /u/test/local/abc -name ab.dat
results:
/u/test/local/abc/pqr/ab.dat
/u/test/local/abc/pqr/xyz/ab.dat
/u/test/local/abc/mno/ab.dat

So need to find compare(see the difference) row by row,and display the diff. SO
/u/dev/local/abc/pqr/ab.dat needs to compared with
/u/test/local/abc/pqr/ab.dat

/u/dev/local/abc/pqr/xyz/ab.dat needs to compared with
/u/test/local/abc/pqr/xyz/ab.dat

and so on.
Please help.:wall:

Thanks

Oh, I see. You want to compare files in /dev/ with their corresponding files in /test/.

find /u/dev/local/abc /u/test/local/abc -name ab.dat |
        sed 's#/u/dev/##g;s#/u/test/##g' | sort -u |
while read LINE
do
        diff /u/dev/"$LINE" /u/test/"$LINE"
done
1 Like

Hi,

I applied the following code so it gives me diffrences for all the file in one go. what would be the command that says there was difference between the two files. The message should be:

"/test/xyz/ab.dat and /dev/xyz/ab.dat has difference."<next line>
<The difference in two files>
"/test/pqr/ab.dat and /dev/pqr/ab.dat has difference."<next line>
<The difference files>

This message can be also redirected to a file.

Thanks,
Varun