Skip to main content
better format.
Source Link
user79743
user79743

MONTHS=(Null Jan Feb ... fill all months here ... Dec) capitalization important. space seprated. Null is a month 0 space filler and has to be there for ease of use later

cd /your/ftp/dir pretty obvious I think

for file in *.wav we are going to loop for .wav files

do start of your loop

your file format is YYYY-MM-DD-HH-MM-SS-xxxxxxxxxx.wav so get the year and month out of filename

year=$(echo ${file} | cut -d"-" -f1)

month=$(echo ${file} | cut -d"-" -f2)

STOREDIR=${year}_${MONTHS[${month}]} create the variable for stopre directory name

if [ -d ${STOREDIR} ] if the directory exists

then

mv ${file} ${STOREDIR} move the file

else if the directory doesn't exist

mkdir ${STOREDIR} create it

mv ${file} ${STOREDIR} then move the file

fi close if statement

done close the for loop.

### capitalization is important. Space separated.
### Null is a month 0 space filler and has to be there for ease of use later.
MONTHS=(Null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)

cd /your/ftp/dir                  ### pretty obvious I think
for file in *.wav                 ### we are going to loop for .wav files
do                                ### start of your loop
    ### your file format is YYYY-MM-DD-HH-MM-SS-xxxxxxxxxx.wav so
    ### get the year and month out of filename
    year=$(echo ${file} | cut -d"-" -f1)
    month=$(echo ${file} | cut -d"-" -f2)
    ### create the variable for store directory name
    STOREDIR=${year}_${MONTHS[${month}]}

    if [ -d ${STOREDIR} ]         ### if the directory exists
    then
        mv ${file} ${STOREDIR}    ### move the file
    elif                          ### the directory doesn't exist
        mkdir ${STOREDIR}         ### create it
        mv ${file} ${STOREDIR}    ### then move the file
    fi                            ### close if statement
done                              ### close the for loop.

MONTHS=(Null Jan Feb ... fill all months here ... Dec) capitalization important. space seprated. Null is a month 0 space filler and has to be there for ease of use later

cd /your/ftp/dir pretty obvious I think

for file in *.wav we are going to loop for .wav files

do start of your loop

your file format is YYYY-MM-DD-HH-MM-SS-xxxxxxxxxx.wav so get the year and month out of filename

year=$(echo ${file} | cut -d"-" -f1)

month=$(echo ${file} | cut -d"-" -f2)

STOREDIR=${year}_${MONTHS[${month}]} create the variable for stopre directory name

if [ -d ${STOREDIR} ] if the directory exists

then

mv ${file} ${STOREDIR} move the file

else if the directory doesn't exist

mkdir ${STOREDIR} create it

mv ${file} ${STOREDIR} then move the file

fi close if statement

done close the for loop.

### capitalization is important. Space separated.
### Null is a month 0 space filler and has to be there for ease of use later.
MONTHS=(Null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)

cd /your/ftp/dir                  ### pretty obvious I think
for file in *.wav                 ### we are going to loop for .wav files
do                                ### start of your loop
    ### your file format is YYYY-MM-DD-HH-MM-SS-xxxxxxxxxx.wav so
    ### get the year and month out of filename
    year=$(echo ${file} | cut -d"-" -f1)
    month=$(echo ${file} | cut -d"-" -f2)
    ### create the variable for store directory name
    STOREDIR=${year}_${MONTHS[${month}]}

    if [ -d ${STOREDIR} ]         ### if the directory exists
    then
        mv ${file} ${STOREDIR}    ### move the file
    elif                          ### the directory doesn't exist
        mkdir ${STOREDIR}         ### create it
        mv ${file} ${STOREDIR}    ### then move the file
    fi                            ### close if statement
done                              ### close the for loop.
Source Link
MelBurslan
  • 7.1k
  • 2
  • 27
  • 35

MONTHS=(Null Jan Feb ... fill all months here ... Dec) capitalization important. space seprated. Null is a month 0 space filler and has to be there for ease of use later

cd /your/ftp/dir pretty obvious I think

for file in *.wav we are going to loop for .wav files

do start of your loop

your file format is YYYY-MM-DD-HH-MM-SS-xxxxxxxxxx.wav so get the year and month out of filename

year=$(echo ${file} | cut -d"-" -f1)

month=$(echo ${file} | cut -d"-" -f2)

STOREDIR=${year}_${MONTHS[${month}]} create the variable for stopre directory name

if [ -d ${STOREDIR} ] if the directory exists

then

mv ${file} ${STOREDIR} move the file

else if the directory doesn't exist

mkdir ${STOREDIR} create it

mv ${file} ${STOREDIR} then move the file

fi close if statement

done close the for loop.

This should be a good starting point for an inexperienced person. Try writing your script in the light of these instructions and commands. You can ask for help if you get stuck