Shell script to move files between two dirs

I have multiple folders which contain subfolders like JAN/ Jan/ FEB/ Feb/ MAR/ Mar/ and so on. I need to move all files from JAN/* to Jan/ , FEB/* to Feb/ and so on. How do I achieve this with a shell script?

Edit
Thanks to @Costas for pointing me in the right direction. His solution will work with Bash 4 and up. Since I had v3 I ended up using this.

for DIR in [A-Z][A-Z]*/
do
    NEWDIR=`echo "$(echo "$DIR" | sed 's/.*/L&/; s/[a-z]*/u&/g')"`
    mv $DIR/* $NEWDIR
done

sed script taken from here.

Answer

For modern bash (which supports case change):

for dir in [A-Z][a-z]*/
do
    mv -t "$dir" ${dir^^}/*
done

In unsupported versions you free to use tr|sed|… conversion instead.

Leave a Reply

Your email address will not be published. Required fields are marked *