I have two directories, dir1 and dir2 with m and n files in them, respectively. the condition may be either m>n or m
I want to diff the files in both the directories and want to store the diffed files in a new directory, diffdir.
So the diffdir should have only files that differs in both the dir.
I used
diff -r dir1 dir2 | grep dir2
It gives me the files that are different in both the directories
diff -r dir1/DISP.case_sc.in.XXX dir2/**DISP.case_sc.in.XXX**
where XXX may varies from 001 to 999 (I have manually added ** here to make the name bold). I need only files (bold one) in diffdir
as number of files in both the directories are not same so in case of m>n it also gives as the output of above command (diff -r dir1 dir2 | grep dir2)
Only in dir2: DISP.case_sc.in.YYY
I also want these DISP.case_sc.in.YYY files in diffdir. Here YYY are the number of files that are equal to the difference m-n. Example if m=020 and n=010 so this YYY will vary from 011 to 020.
In both the dirs (1&2) some files will be exactly same that are not printed with the diff command, I need those files in a another directory name nodiffdir.
Sample input with files named to indicate their relationship to each other:
dir1
dir1_only
comm_diff
comm_same
dir2
dir2_only
comm_diff
comm_same
Expected output (dir1 and dir2 left unchanged):
samedir
comm_same # copied as-is from dir1 or dir2
diffdir
comm_diff # output of "diff dir1/comm_diff dir2/comm_diff"
dir1_only # copied as-is from dir1
dir2_only # copied as-is from dir2