I am running diff between two directories dir1 and dir2.
diff --exclude --recursive --brief -b dir1 dir2
The output of the above command is
Files dir1/java/abc/bcd/abc9991.java and dir2/java/abc/bcd/abc9991.java differ
Files dir1/java/abc/bcd/abc9933.java and dir2/java/abc/bcd/abc9933.java differ
Only in dir2/ora/dpc: g025_abc.dpc
Only in dir2/ora/dpc: gc_cvb_jrp_1650_abc.dpc
Only in dir2/ora/dpc: gc_k_jrp_502901690_abc.dpc
Files dir1/ora/ps/abc_bcda640921_bcd.sp and dir2/ora/ps/abc_bcda640921_bcd.sp differ
Files dir1/ora/ps/cvg_fgh640931_drv_msd.sp and dir2/ora/sp/cvg_fgh640931_drv_msd.sp differ
Want to extract file names from the diff output based on file extensions(have over 6 extensions in the subdirectories .java,.dpc,.cvg, and so on)
and delete all the files in dir2 except these in the diff output.
example: from the above diff output I want to extract files
abc9991.java
gc_cvb_jrp_1650_abc.dpc
gc_k_jrp_502901690_abc.dpc
abc_bcda640921_bcd.sp
cvg_fgh640931_drv_msd.sp from dir2 and delete rest of the files from dir2.
Tried using the cut command but too many sub directories inside and each time the position has to change.
Common subdirectories: dir1/aix and dir2/aix
Common subdirectories: dir1/envsql and dir2/envsql
Common subdirectories: dir1/java and dir2/java
Common subdirectories: dir1/ora and dir2/ora
I see no files being deleted. There are many files that are similar in dir1 and dir2 and none of them got deleted.
Attached is the zip I created for your reference. It has two directories dir_1 and dir_2. If a compare is run between dir_1 and dir_2 , the only files that should be present in dir_2 after the compare should be the files inside dir_2/ora/seq/
What is the --exclude for? With no parameters that appears to be excluding everything, at least on my diff (GNU diffutils 3.3).
Without that it works as expected:
$ diff -s --recursive -b dir_1 dir_2
Files dir_1/java/abc/test/Constants.java and dir_2/java/abc/test/Constants.java are identical
Files dir_1/java/abc/test/constants_1.txt and dir_2/java/abc/test/constants_1.txt are identical
Files dir_1/java/abc/test/delete.java and dir_2/java/abc/test/delete.java are identical
Files dir_1/java/abc/test/test.java and dir_2/java/abc/test/test.java are identical
Only in dir_1/ora: java
Only in dir_2/ora: seq
$ diff -s --recursive -b dir_1 dir_2 | awk '/identical$/ {print $4}' | xargs echo rm
rm dir_2/java/abc/test/Constants.java dir_2/java/abc/test/constants_1.txt dir_2/java/abc/test/delete.java dir_2/java/abc/test/test.java