#!/usr/bin/env bash #Sac Peak Solar Observatory # EXAMPLES: # # run on only one year in test mode # ./kh_rename 1980 1980 test | less # # run on only one year in actual move mode # ./sacp_rename 1980 1980 #NEW COMMENT # # run several years in test mode # ./sacp_rename 1980 2010 test | less # # run several years in actual move mode # ./sacp_rename 1947 2004 # #This script will rename files from 19990101_sp.pdf to sacp_drawx_fd_19990101_xxxx.pdf #Years of data are 1947 - 2004 #Where there exists spb or spc after the date, open drawing and input actual time, if b or c don't exist then #input xxxx for time debug=0 start_year=1947 stop_year=2004 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} if [ "`echo *.pdf`" != "*.pdf" ] then for file in *.pdf do f1="`echo $file | sed 's/_/ /g' | awk '{print $1}'`" if [[ "${file}" =~ "sacp.*" ]] then : else numfiles="`echo *${f1}* | wc -w`" if [ $numfiles -gt 1 ] then f2="`echo ${file} | sed 's/.pdf//g'`" mv ${file} sacp_drawx_fd_${f2}_xxxx.pdf else f2="sacp_drawx_fd_${f1}_xxxx.pdf" mv ${file} ${f2} fi fi done fi cd ../.. done done