I have several files with different extensions and directories with the same basename, like this example.
FileA.txt
FileA.html
FileA.directory/
FileB.txt
FileB.html
FileB.directory/
FileC.txt
FileC.html
FileC.directory/
And i would like to create a for-loop for which i can move all files to their corresponding directory based on their basename. Resulting in the following
FileA.directory/FileA.txt
FileA.directory/FileA.html
FileB.directory/FileB.txt
FileB.directory/FileB.html
FileC.directory/FileC.txt
FileC.directory/FileC.html
I've tried to find several suggestion which are kind of similar to my problem on this page, like this example. But i can't find a completely similar question.
for dir in .*/
do
for f in "$dir"*
do
base=${f#$dir}
mv "$base.*" "$dir"
done
done
However I can't get it to work.