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?

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]*/
    NEWDIR=`echo "$(echo "$DIR" | sed 's/.*/L&/; s/[a-z]*/u&/g')"`
    mv $DIR/* $NEWDIR

sed script taken from here.


For modern bash (which supports case change):

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

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 *