I am trying to find a way to move files into corresponding date files.
i=0
while read line
do
array[ $i ]="$line"
(( i++ ))
done < <(ls)
cd $(echo ${array[1]})
echo ${array[1]}}
pwd
#cd "$(array[1]}"
[[ -d 2015 ]] || mkdir 2015
cd "2015"
[[ -d 02-February ]] || mkdir 02-February
[[ -d 03-March ]] || mkdir 03-March
[[ -d 04-April ]] || mkdir 04-April
[[ -d 05-May ]] || mkdir 05-May
[[ -d 06-June ]] || mkdir 06-June
[[ -d 07-July ]] || mkdir 07-July
[[ -d 08-August ]] || mkdir 08-August
[[ -d 09-September ]] || mkdir 09-September
[[ -d 10-October ]] || mkdir 10-October
[[ -d 11-November ]] || mkdir 11-November
[[ -d 12-December ]] || mkdir 12-December
cd ".."
Here is where I want to move the files. I can make it work by using something like this while in directory that contains the files:
for file in *; do
if [[ "$file" =~ 03-[0-9][0-9]-2015 ]]; then
varx=`echo $file|head -1|cut -d- -f 4|sed 's/.txt//g'`;
vary=`echo $file|head -1|cut -d ' ' -f 2|sed 's/-.*//'`;
jx=$(varz=`echo $vary`; if [[ $varz =~ $vary ]]; then echo $varz-March;fi)
echo mv "$file" /tmp/Safe\ Dirs/${array[1]}/$varx/$jx
fi
done
However, I need to to go through every directory that has date files and move them into the /tmp/Safe\ Dirs/subdir1 subdir2 subdir3 etc folders.
So we have
/tmp/Safe\ Dirs/subdir1
/tmp/Safe\ Dirs/subdir2
/tmp/Safe\ Dirs/subdir3
/tmp/Safe\ Dirs/subdir4
and every file that corresponds to a certain month needs to be moved to the 2015/02-February etc. folder
This works, but I have to indicate the index of the array in each statement. I'm not sure how to move the files that are in each directory into the directories represented by the element of the array.
So these are a sample of the directories:
/tmp/Safe\ Dirs/vault/file-02-12-15
/tmp/Safe\ Dirs/vault/file-03-15-15
/tmp/Safe\ Dirs/lock/file-02-12-15
/tmp/Safe\ Dirs/lock/file-03-18-15
These need to be moved into:
/tmp/Safe\ Dirs/vault/02-February
/tmp/Safe\ Dirs/vault/03-March
and
/tmp/Safe\ Dirs/lock/02-February
/tmp/Safe\ Dirs/lock/03-March
So what happens is that I need to use these statements, etc.
mv "$file" /tmp/Safe\ Dirs/${array[1]}}/$varx/$jx
mv "$file" /tmp/Safe\ Dirs/${array[2]}}/$varx/$jx
mv "$file" /tmp/Safe\ Dirs/${array[3]}}/$varx/$jx
I'm sure there is a much easier way to do this. Any suggestions?