I am trying to figure out a way to script copying specific files from one dir structure to another.
I have a dir structure like this:
dira/author 1/book 1/file a.epub
/book 2/file b.epub
/author 2/book 1/file c.epub
/author 3/book 1/file d.epub
/book 2/file e.epub
/book 3/file f.epub
<etc....>
The result I am looking for is:
dirb/author 1/file a.epub
/file b.epub
/author 2/file c.epub
/author 3/file d.epub
/file e.epub
/file f.epub
<etc....>
Currently I just use a quick script to cp the files up one level in the "dira" file structure, dupe it to "dirb" and then clean it up manually:
find . -type f -name "*.epub" |while read file
do
cp "$file" "${file%/*}"/../
done
I could do something like this to create the new dir structure:
find . -type f -name "*.epub" -printf "%P\n" > $books
cd dir2
awk -F / '{ print $2 }' $books | xargs $DEBUG mkdir -p
but I am stumped on copying the files into that structure. :wall: