i trying search set of files same name between 2 directories
**dir1** (/myfolder/sample/test1) file1.txt file2.txt file3.txt file4.txt **dir2** (/myfolder/sample/test2) file1.txt file4.txt
i using diff command in following way
diff -sr /myfolder/sample/test1/ /myfolder/sample/test2/ | awk -f: '{print $1}' | grep -r ".txt"
the result follows:
files /myfolder/sample/test1/file1.txt , /myfolder/sample/test2/file1.txt identical files /myfolder/sample/test1/file4.txt , /myfolder/sample/test2/file4.txt identical
the result looking file name:
file1.txt file4.txt
any appreciated!!
a little fiddling ls & grep should work too:
ls dir1 | grep "`ls dir2`"
or, if it's c shell:
ls dir1 | grep -e "`ls dir2 | tr '\n' '|'` "
as observed radical7, first method wouldn't work in c shell, newlines lost while passing grep. such cases use regex, instead.
grep -e
or egrep
allows use regex of form file1.txt|file2.txt
pattern.
also, note whitespace @ end intentional.
Comments
Post a Comment