1

I have a bunch of excel files I would like to extract recursively from all subdirectories, keeping the directory/file name as the new directory name for all extracted files of each xlsx.

to extract a file I found this. Unfortunately my bash knowledge lacks the skill to so all in one command.

So I tried to split it up in smaller parts first:

for z in ./*
do name="${z%%_*}"; dest=".${name//[ .-]/}"; mkdir "$dest";
done

if I try that the * in

for z in ./*

searches for all files in the current directory and not like I had anticipated the result from

find . -name "*.xlsx"

so I tried if I could maybe reverse it:

for f in | find . -name "*.xlsx"; do d="${f}"; mkdir -p "$d"

but it obviously doesn't work cause my piping is wrong

1

Don't know if your split with bash is right.

Because I have stopped working with bash a long time ago.

But when you want the output of find in a loop, try this :

find . -name '*.xlsx' -print0 |
    while IFS= read -r -d $'\0' z; do
        name="${z%%_*}" 
        dest=".${name//[ .-]/}" 
        mkdir "$dest"
    done
  • You can also just do: for i in $( find . -name '*.xlsx' ). But you could run into issues if your filenames and/or directory names have spaces in them. – LJKims Jun 9 '17 at 12:32
  • guided me into the right direction – aldr Jun 12 '17 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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