#!/usr/bin/env bash # # EXAMPLES: # # run on only one year in test mode # ./kh_rename 1980 1980 test | less # # run on only one year in actual move mode # ./kh_rename 1980 1980 # # run several years in test mode # ./wend_rename 1980 2010 test | less # # run several years in actual move mode # ./wend_rename 1947 1987 # #This script will rename files from 1972 thru 2009, going from yyyymmdd_time_NL.pdf to #boul_neutl_fd_yyyymmdd_time.pdf #the else at the bottom of the script says that if a month (diretory of 01 - 12) does not exist, continue on. #added f3 because this dataset has 3 tokens, 1 is yyyymmdd, 2 is adding the boul_neutl_fd_ to each file, and 3. is #keeping the time. debug=0 start_year=1972 stop_year=2009 cwd=`pwd` if [ -z "$1" ]; then echo "ERROR: no start year specified" echo "This script expects to be run from a top level directory, with folders of the form YYYY/MM below it" echo "USAGE: ${0} " echo "EXAMPLE: ${0} 1980 1982" fi if [ -z "$2" ]; then echo "ERROR: no stop year specified" echo "This script expects to be run from a top level directory, with folders of the form YYYY/MM below it" echo "USAGE: ${0} " echo "EXAMPLE: ${0} 1980 1982" fi if [ ! -z "${3}" ]; then debug=1 fi start_year="${1}" stop_year="${2}" for yr in `seq ${start_year} ${stop_year}` do for mo in `seq -w 01 12` do path="${yr}/${mo}" if [ -d ${path} ] then cd ${path} for file in * do f1="`echo $file | sed 's/_/ /g' | awk '{print $1}'`" f3="`echo $file | sed 's/_/ /g' | awk '{print $2}'`" f2="boul_neutl_fd_${f1}_${f3}.pdf" if [[ "${file}" =~ "boul.*" ]] then : else mv $file $f2 fi done cd ../.. else echo "${path} does not exist, continuing" fi done done