Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

There are two folders named Folder1 and Folder2. Folder1 has files with name:For example S-080001-0-0.xml with its corresponding same files in Folder2 named S-080001-0-0.xml

The change in Folder2 is that,for same file in Folder1 which is S-080001-0-0.xml,Folder 2 contains multiple files with different value after hyphen,like -080001-0-0.xml,-080001-0-1.xml,-080001-0-2.xml,-080001-0-3.xml. My challenge is to move all the files of same name from these two folders.

share|improve this question
    
Please explain. Do you want to add Folder1/S-080001-0-0.xml after, e.g., Folder2/S-080001-0-5.xml as Folder2/S-080001-0-6-xml? Combine them somehow? –  vonbrand Feb 26 '13 at 10:19
add comment

1 Answer 1

If you want to compare based on filename then you can use below :

find folder1/ folder2/ -type f -printf %f"\n" | sort |  uniq -c | \
awk '( $1 >= 2 ) {print "mv -vf folder1/"$2,"other_dir/","&&","mv -vf folder2/"$2,"other_dir/"}'

it will just print command on terminal , it will not execute that , if you see output is proper then just append | sh at the last then it will execute that command

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.