I have several files like
Chocolate-RS33 and others in my home directory that are pulled from an ftp server. In the same home directory there are Folders like
Sweet, etc. And within these folders, there are subfolders with names like
I need to run a script on my home directory such that once I have
Apple-AP01, it knows to place it into the Fruit folder based on the "
AP" keyword and then further place that into the
Apple-AP01 folder. and for
Chocolate-RS33, it needs to go into the
Sweet folder based on the "
RS" keyword and then further into the
Chocolate-RS33 subfolder within the
Sweet folder. I need this for all of my files. Can someone put a bash script that would work?
for f in *. do name=`echo "$f"|sed 's/ -.*//'` letter=`echo "$name"|cut -c1` dir="DestinationDirectory/$letter/$name" mkdir -p "$dir" mv "$f" "$dir" done
I think I need to use a
for loop, but I’m not sure how to do it in bash.