Find all pdf an get make a folder from filename substring

Hi ,

i need your advice.

i will find all *.pdf files and make a folder for every different prefix of file names.

for example:

test_21424234.pdf
new_242342.pdf

at the and i will that i create ( if not exits ) a new folder " test " and " new " , afterwards i will move the file in this new folder.

i hope you kann help me

so long Maxwill

PS: sry for my engilsh

Welcome to the forum.

Any attempts / ideas / thoughts from your side?

Hi,

yes i have bulid this

VAR=`find . -name *.pdf -print`
for file in $VAR;
do
   fname=`basename $file`
   prefix=${fname%_*}
   mkdir -p ./$prefix
   mv $file ./$prefix/
done

but i get a problem when i have files like :

test_234234_22433.pdf

i will only the first letters until the first underscore.

so long Maxwill

Have you tried:

prefix=${fname%%_*}

?