UPDATE / EDIT
Used the following script:
#!/usr/local/bin/bash
src=upload2website
dst=uploads
prefix=FB_
# find all files in src dir
gfind "$src" -maxdepth 1 -type f -printf "%f\n" |
# remove all the `FB_`
sed 's@^FB_@@; s/_FB\.jpg$//;' |
sort |
# filter from the list the files from dst
# output only paths
join -t$'\t' -11 -21 -o2.2 - <(
# a newline separated list with two tab separated columns
gfind "$src" -maxdepth **5** -mindepth 2 -type f -printf '%f\t%p\n' |
# sort on filename
sort -k1
) |
# copy the files
xargs -I{} echo cp {} "$dst"
~
~
~
"stack.sh" 20L, 518C written
The output (just put all output for the sake of clarity). Sorry for the worse lay-out. As you can see, it copies .DS_Store files too and these should not be selected, however these are easy to remove in de uploads-folder.
➜ Documents ./stack.sh cp upload2website/40MijlvanBru/.DS_Store
uploads cp upload2website/8Uur van de Oosterschelde/.DS_Store uploads
cp upload2website/Almere Regatta 2015/.DS_Store uploads cp
upload2website/Antwerpen-2019/.DS_Store uploads cp
upload2website/Antwerpen/.DS_Store uploads cp
upload2website/Beaucette-Lezardrieux/.DS_Store uploads cp
upload2website/Bembridge - Cowes/.DS_Store uploads cp
upload2website/Bocht van Guinea/.DS_Store uploads cp
upload2website/Boiler Isotemp/.DS_Store uploads cp
upload2website/Boot/.DS_Store uploads cp
upload2website/Boulogne/.DS_Store uploads cp
upload2website/Burnham-on-Crouch - Vlissingen/.DS_Store uploads cp
upload2website/Carteret-Dielette/.DS_Store uploads cp
upload2website/Elektra/.DS_Store uploads cp
upload2website/GrandcampMaisy-Ouistreham/.DS_Store uploads cp
upload2website/Herkingen, Zuid-Holland - Jachthaven, 3 februari
2018/.DS_Store uploads cp upload2website/JWvdM/.DS_Store uploads cp
upload2website/Kajuitramen/.DS_Store uploads cp
upload2website/Kiel/.DS_Store uploads cp
upload2website/Koelkast/.DS_Store uploads cp
upload2website/Kuip/.DS_Store uploads cp upload2website/Lazy
bag/.DS_Store uploads cp
upload2website/Littlehampton-BirdhamPool/.DS_Store uploads cp
upload2website/Lummelbeslag/.DS_Store uploads cp
upload2website/Lymington/.DS_Store uploads cp
upload2website/Middelburg-Veere/.DS_Store uploads cp
upload2website/Nieuwpoort-Blankenberge/.DS_Store uploads cp
upload2website/Onderwaterschip/.DS_Store uploads cp
upload2website/Onweer_NVvT/.DS_Store uploads cp
upload2website/Overtocht DCS/.DS_Store uploads cp
upload2website/Pasen_2019/.DS_Store uploads cp
upload2website/PropOne-antifouling/.DS_Store uploads cp
upload2website/Roer/.DS_Store uploads cp
upload2website/Roer/Roer/.DS_Store uploads cp upload2website/Rondje
Engeland/.DS_Store uploads cp upload2website/Rondje
Engeland/001-Vertrek-Lowestoft/.DS_Store uploads cp
upload2website/Rondje Engeland/003-Wells-next-the-Sea/.DS_Store
uploads cp upload2website/Rondje
Engeland/006-Whitby-Newcastle/.DS_Store uploads cp
upload2website/Rondje Engeland/007-Newcastle/.DS_Store uploads cp
upload2website/Rondje Engeland/008-Newcastle-Amble/.DS_Store uploads
cp upload2website/Rondje Engeland/012-Edinburgh-Arbroath/.DS_Store
uploads cp upload2website/Rondje Engeland/016-Peterhead/.DS_Store
uploads cp upload2website/Rondje Engeland/018-Lossiemouth/.DS_Store
uploads cp upload2website/Rondje Engeland/024-Caledonian Canal-Fort
Augustus/.DS_Store uploads cp upload2website/Rondje
Engeland/026-Laggan Lock-Banavie/.DS_Store uploads cp
upload2website/Rondje Engeland/028-Banavie-Corpach Basin/.DS_Store
uploads cp upload2website/Rondje Engeland/029-Corpach
Basin-Dunstaffnage/.DS_Store uploads cp upload2website/Rondje
Engeland/031-Tobermory/.DS_Store uploads cp upload2website/Rondje
Engeland/036-Lamlash/.DS_Store uploads cp upload2website/Rondje
Engeland/038-Campbeltown-Belfast/.DS_Store uploads cp
upload2website/Rondje Engeland/039-Belfast/.DS_Store uploads cp
upload2website/Rondje Engeland/042-Dublin/.DS_Store uploads cp
upload2website/Rondje Engeland/050-Padstow-Newlyn/.DS_Store uploads cp
upload2website/Rondje Engeland/052-Fowey-Dartmouth/.DS_Store uploads
cp upload2website/Rondje Engeland/053-Dartmouth-Weymouth/.DS_Store
uploads cp upload2website/Rondje
Engeland/057-Eastbourne-Dover/.DS_Store uploads cp
upload2website/Rondje Engeland/061-St_Annaland-Herkingen/.DS_Store
uploads cp upload2website/Rondje Engeland/Krabbeltje/.DS_Store uploads
cp upload2website/Rondje Kanaal 2012/.DS_Store uploads cp
upload2website/Schroef/.DS_Store uploads cp
upload2website/StVaast-GrandcampMaisy/.DS_Store uploads cp
upload2website/Te water/.DS_Store uploads cp
upload2website/Toilet/.DS_Store uploads cp
upload2website/Uisge/.DS_Store uploads cp
upload2website/Uisge/40Myl/.DS_Store uploads cp
upload2website/Uisge/UK/.DS_Store uploads cp upload2website/VDO
Urenteller/.DS_Store uploads cp upload2website/Vakantie 2014/.DS_Store
uploads cp upload2website/Vakantie 2015/.DS_Store uploads cp
upload2website/Veere/.DS_Store uploads cp
upload2website/Verkoop/.DS_Store uploads cp
upload2website/Verzekeringscasus/.DS_Store uploads cp
upload2website/Zomer 2016/.DS_Store uploads cp
upload2website/Zomervakantie/.DS_Store uploads cp upload2website/27
apr. 2007/1213030320_dscf1547_small.jpg uploads cp
upload2website/Uisge/2.jpg uploads cp upload2website/Uisge/3.jpg
uploads cp upload2website/40MijlvanBru/40MijlvanBru-27.jpg uploads cp
upload2website/40MijlvanBru/40MijlvanBru-31.jpg uploads cp
upload2website/8Uur van de
Oosterschelde/8UurvandeOosterschelde-035.jpg uploads cp
upload2website/Antwerpen-2019/Antwerpen-2019-14.jpg uploads cp
upload2website/Antwerpen-2019/Antwerpen-2019-38.jpg uploads cp
upload2website/Boiler Isotemp/Boiler-01.jpg uploads cp
upload2website/Boiler Isotemp/Boiler-07.jpg uploads cp
upload2website/Dek schilderen/Dek schilderen - 20.jpg uploads cp
upload2website/Fenderhoes/Fenderhoes-08.jpg uploads cp
upload2website/Herkingen, Zuid-Holland - Jachthaven, 3 februari
2018/Heat-exchanger-06.jpg uploads cp upload2website/Honfleur/Honfleur
- 21.jpg uploads cp upload2website/09april16/IMG_3799.jpg uploads cp upload2website/Kajuitramen/Kajuitramen - 92.jpg uploads cp
upload2website/Kajuitramen/Kajuitramen - 95.jpg uploads cp
upload2website/Kajuitramen/Kajuitramen±-±21.jpg uploads cp
upload2website/Aanhechting kiel romp/Kitrand_romp_kiel-01.jpg uploads
cp upload2website/Koelkast/Koelkast - 15.jpg uploads cp
upload2website/Koelkast/Koelkast - 30.jpg uploads cp
upload2website/Koelkast/Koelkast - 36.jpg uploads cp
upload2website/Lummelbeslag/Lummelbeslag - 09.jpg uploads cp
upload2website/Onderwaterschip/Onderwaterschip-48.jpg uploads cp
upload2website/Pasen_2019/Pasen_2019-15.jpg uploads cp
upload2website/PropOne-antifouling/PropOne-antifouling-06.jpg uploads
cp upload2website/Radiateur/Radiateur - 01.jpg uploads cp
upload2website/Radiateur/Radiateur - 02.jpg uploads cp
upload2website/Radiateur/Radiateur - 03.jpg uploads cp
upload2website/Radiateur/Radiateur - 04.jpg uploads cp
upload2website/Radiateur/Radiateur - 05.jpg uploads cp
upload2website/Tewaterlating/Tewaterlating-01.jpg uploads cp
upload2website/Uisge/Uitslag-Marathon2012.jpg uploads cp
upload2website/Vakantie 2014/Vakantie 2014 - 129.jpg uploads cp
upload2website/Waterpomp/Waterpomp - 4.jpg uploads cp
upload2website/Waterpomp/Waterpomp - 5.jpg uploads cp
upload2website/Zomer 2016/Duinkerken - Boulogne sur Mer/Zomer 2016 -
096.jpg uploads cp upload2website/Zomervakantie/Zomervakantie-09.jpg uploads cp upload2website/Zomervakantie/Zomervakantie-119.jpg uploads
cp upload2website/Zomervakantie/Zomervakantie-135.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-142.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-144.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-15.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-158.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-162-test.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-22.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-24.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-30.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-47.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-64.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-82.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-87.jpg uploads cp
upload2website/Zomervakantie/Zomervakantie-93.jpg uploads
If I count the number of files copied, I'm missig around 90 files. I don't know how to add a text file to this post otherwise I could show the files containing (AA_ of AA) actually FB or _FB but that's of no importance to the solution. It might be even so to take all *.jpg files from the upload2website folder and see if there is a occurence in one of the subfolders below upload2website.
** UPDATE 03jan20 **
Managed to modify the script to exclude files starting with a dot:
#!/usr/local/bin/bash
src=upload2website
dst=uploads
prefix=FB_
# find all files in src dir
# gfind "$src" -maxdepth 1 -type f -printf "%f\n" |
gfind "upload2website" -maxdepth 1 -type f \( ! -iname ".*" -iname "*.jpg" \) -printf "%f\n" |
# remove all the `FB_`
# sed 's@^FB_@@; s/FB//; s/_FB\.jpg$//;' |
sed 's@^FB_@@; s/FB//; s/_FB\.jpg$//;' |
sort |
# filter from the list the files from dst
# output only paths
join -t$'\t' -11 -21 -o2.2 - <(
# a newline separated list with two tab separated columns
gfind "$src" -mindepth 2 -type f -printf '%f\t%p\n' |
# sort on filename
sort -k1
) |
# copy the files
xargs -I{} echo cp {} "$dst"
I think the join is missing some file, because
➜ Documents gfind "upload2website" -maxdepth 1 -type f \( ! -iname ".*" -iname "*.jpg" \) -printf "%f\n" | sed 's@^FB_@@; s/FB//; s/_FB\.jpg$//;' | sort > tmp.txt
gives alle requested files from upload2website, however I'm missing a search to the files in f.i. the following folders: (again, sorry for the poor lay-out).
➜ Documents l upload2website/Rondje\ Engeland/ total 5236192 drwxr-xr-x 89 gjdegraaf staff 2,8K 2 jan 22:11 . drwxr-x-wx@ 431 gjdegraaf staff 13K 2 jan 22:27 .. drwxr-xr-x 25 gjdegraaf staff 800B 2 jan 22:11 001-Vertrek-Lowestoft drwxr-xr-x 13 gjdegraaf staff 416B 6 jun 2019 002-Lowestoft-Wells-next-the-Sea drwxr-xr-x 74 gjdegraaf staff 2,3K 2 jan 22:11 003-Wells-next-the-Sea drwxr-xr-x 12 gjdegraaf staff 384B 10 jun 2019 004-Wells-next-the-Sea-Whitby drwxr-xr-x 21 gjdegraaf staff 672B 15 jun 2019 005-Whitby drwxr-xr-x 9 gjdegraaf staff 288B 2 jan 22:11 006-Whitby-Newcastle drwxr-xr-x 56 gjdegraaf staff 1,8K 2 jan 22:11 007-Newcastle drwxr-xr-x 20 gjdegraaf staff 640B 2 jan 22:11 008-Newcastle-Amble drwxr-xr-x 26 gjdegraaf staff 832B 24 jun 2019 009-Amble drwxr-xr-x 25 gjdegraaf staff 800B 24 jun 2019 010-Amble-Edinburgh drwxr-xr-x 19 gjdegraaf staff 608B 26 jun 2019 011-Edinburgh drwxr-xr-x 12 gjdegraaf staff 384B 2 jan 22:11 012-Edinburgh-Arbroath drwxr-xr-x 18 gjdegraaf staff 576B 28 jun 2019 013-Arbroath drwxr-xr-x 10 gjdegraaf staff 320B 29 jun 2019 014-Arbroath-Peterhead drwxr-xr-x 20 gjdegraaf staff 640B 30 jun 2019 015-Aberdeen-Peterhead drwxr-xr-x 28 gjdegraaf staff 896B 2 jan 22:11 016-Peterhead drwxr-xr-x 10 gjdegraaf staff 320B 6 jul 07:41 017-Peterhead-Lossiemouth drwxr-xr-x 44 gjdegraaf staff 1,4K 2 jan 22:11 018-Lossiemouth drwxr-xr-x 7 gjdegraaf staff 224B 12 jul 19:08 019-Lossiemouth-Cromarty drwxr-xr-x 20 gjdegraaf staff 640B 17 jul 08:24 020-Cromarty drwxr-xr-x 7 gjdegraaf staff 224B 17 jul 08:27 021-Cromarty-Rosemarkie Bay drwxr-xr-x 11 gjdegraaf staff 352B 17 jul 08:28 022-Rosemarkie Bay-Inverness drwxr-xr-x 20 gjdegraaf staff 640B 19 jul 06:34 023-Inverness-Caledonian Canal drwxr-xr-x 34 gjdegraaf staff 1,1K 2 jan 22:11 024-Caledonian Canal-Fort Augustus drwxr-xr-x 27 gjdegraaf staff 864B 22 jul 08:04 025-Fort Augustus-Laggan Lock drwxr-xr-x 12 gjdegraaf staff 384B 2 jan 22:11 026-Laggan Lock-Banavie drwxr-xr-x 61 gjdegraaf staff 1,9K 25 jul 08:01 027-Ben Nevis drwxr-xr-x 14 gjdegraaf staff 448B 2 jan 22:11 028-Banavie-Corpach Basin drwxr-xr-x 20 gjdegraaf staff 640B 2 jan 22:11 029-Corpach Basin-Dunstaffnage
Could someone help me with the join in the script? I do understand how a join works, however not in scripting. Thanks!
cp upload2website/AA_bestandsnaamA-68.jpg uploads cp upload2website/AA_bestandsnaamB - 01.jpg uploads cp upload2website/AA_bestandsnaamC-106.jpg uploads
should be the output from your script? Please try not to describe, rather please show what should happen. orcp upload2website/folder1/bestandsnaamA-68.jpg uploads cp upload2website/folder2/bestandsnaamB - 01.jpg uploads cp upload2website/folder3/bestandsnaamC-106.jpg uploads
? And why you describe the prefix to beAA_
yet your script hasFB_
? – KamilCuk