#!/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 19990101_DWN.pdf to wend_compo_fd_19990101_.pdf #Years of data are 1947 - 1987 debug=0 start_year=1947 stop_year=1987 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}" cd ${path} for file in *.pdf do f1="`echo $file | sed 's/_/ /g' | awk '{print $1}'`" f2="wend_compo_fd_$f1.pdf" if [[ "${file}" =~ "wend.*" ]] then : else mv $file $f2 fi done cd ../.. done done