Results 1 to 4 of 4
Hi, all:
I've got two folders, folder A contains some image files (say, 100 files) in .jpg format;
folder B contains all description files (say, 500 files) in .txt format.
...
- 06-20-2010 #1Just Joined!
- Join Date
- Dec 2006
- Location
- Surrey, BC, Canada
- Posts
- 3
copy all files with the same filenames as those in another folder
Hi, all:
I've got two folders, folder A contains some image files (say, 100 files) in .jpg format;
folder B contains all description files (say, 500 files) in .txt format.
All image files in folder A are able to find their corresponding description files in folder B.
That is to say, regardless of file extension, 100 .txt files in folder B share the same name as those 100 .jpg files, for example 00011020.jpg in folder A is able to find its corresponding 00011020.txt in folder B.
Now, my question is:
How to just copy out the 100 description .txt files that share the same name as those 100 image files, out from folder B into folder C( or create folder C first, and then carry out the copy) ?
Looking forward to your help.
Best Regards
JIA Pei
- 06-20-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
School work?
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-20-2010 #3Just Joined!
- Join Date
- Dec 2006
- Location
- Surrey, BC, Canada
- Posts
- 3
Haha...
not at all.
My task.
Sorry, I'm not a specialist in script.
- 06-20-2010 #4
Hmm,
in dubio pro reo
This oneliner is hack-ish as it lives on certain assumptions and has no errorchecking.
Also, the multiple cp can be optimized.
So dont use that as a cronjob and just for one time shots
Assumptions
- directories A, B and C exist
- and are on the same level
- the script is called from the directory containing A,B and C
Code:for FILE in `find A/ -type f -iname "*.jpg" |sed s#A/##| sed s/\.jpg$// | sort |uniq`; do cp B/$FILE.txt C/;done
You must always face the curtain with a bow.


Reply With Quote