Write a shell script which gets the files as parameters:
#!/bin/bash
for filepath; do
parentpath="${filepath%/*}"
if [ "$parentpath" != "$filepath" ]; then # $file contains a /
file="${filepath#"$parentpath"/}"
else
file="$filepath"
parentpath=""
fi
filename="${file%.*}"
if [ -z "$parentpath" ]; then
mkdir -p "$filename" && mv "$file" "$filename"
else
mkdir -p "${parentpath}/$filename" &&
mv "$filepath" "${parentpath}/$filename"
fi
done
You can call this script as `./script *.ext1 *.ext2 *.ext3` for not too huge numbers of files or as `find ... -exec ./script {} +` for huge numbers.