On Mar 16, 9:32 am, "Deepu" <pradeep...@gmail.com> wrote:
> > There is a unix utility called "dircmp" which does basic directory
> > comparision , but assuming you are looking for just file comparision
> > within different directories, have you tried using diff or sdiff
> > ( sdiff is much more readable as it shows side by side comparision).A
> > simple for loop ( in shell or foreach in perl) . You can obviusly
> > pretty it up by cleaning up the syntax and including more error
> > checking..
>
> > in shell,
> > for i in 1..10
> > do
> > echo "##Comparing FILENAME_$i in DIR1 and DIR2##"
> > sdiff /DIR1/FILENAME_$i.a /DIR2/FILENAME_$i.x
> > done | tee <output>
>
> > in perl,
> > foreach (1..10) {
> > print "##comparing FILENAME_$i in DIR1 and DIR2##";
> > `sdiff /DIR1/FILENAME_$i.a /DIR2/FILENAME_$i.x >> /tmp/somefile`;
> > }
>
> How to do this ONLY after checking files with same name exists in both
> directories else display FILENAME doesnot exist in DIR1/2- Hide quoted text -
>
> - Show quoted text -
perl -lne '
s{^/(?

DIR2)|DIR1)/(.*?)\.[^.]*$}{$2};
$seen{$2}=1 and next if defined $1;
print "$2 of DIR1 is ", !$seen{$2}&&"not ", "present in DIR2"
' /DIR2/*.x /DIR1/*.a
FILENAME_1 of DIR1 is present in DIR2
FILENAME_2 of DIR1 is present in DIR2
FILENAME_3 of DIR1 is present in DIR2
FILENAME_4 of DIR1 is not present in DIR2
Regards,
Xicheng