bash - find+xargs: for all files in a dir find pair in other nested dir and move there -


i have directory "images" nested structure, , there .png files somewhere in it. have plain directory "svg" bunch of .svg files in it. need move each .svg file same dir lies .png file same name.

this command single given .svg file works:

find /images -name 'sample.png' | grep -v thumb | xargs -i{} dirname {}|xargs -0 -i {}  mv /svg/sample.svg {} 

grep -v thumb applied because each .png file there thumbnail file same name in other subdir named "thumb".

i tried write command files:

find /svg/ -name "*.svg" -exec basename {} '.svg' \; | xargs -o -i {} "find /images/ -name {}" 

but recieve , error: `basename' terminated signal 13

moreover, if second command works, next step combine first command, here problem: how can send given filename final command "mv" (see {???} in code)?

find /svg/ -name "*.svg" -exec basename {} '.svg' \; | xargs -o -i {} "find /images/ -name {}" | grep -v thumb | xargs -i{} dirname {}|xargs -0 -i {}  mv /svg/{???} {} 

this bash script should work. solution cannot stuffed pipeline:

#! /bin/bash svg in svg/*.svg ;     name=${svg##*/}                                  # remove path.     name=${name%.svg}                                # remove extension.     png=$(find -name $name.png -not -path '*thumb*')     dir=${png%$name.png}                             # remove filename.     mv "$svg" "$dir" done 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -