#!/usr/bin/env bash # # EXAMPLES: # # #This script will rename files from 19560101_DSS.PDF to nwob_compo_fd_19990101_.pdf #Years of data are 1956 - 1973 #This script looks for the _(underscores) and removes them and whatever comes directly after them. It then inputs #frib_drawx_fd_ before the yyyymmdd. If the script finds a file already beginning with nwob, it will be ignored. #If there is no data in a month, it will show an error but continue running. start_year="${1}" stop_year="${2}" for yr in `seq -w ${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}'`" f2="nwob_compo_fd_$f1.pdf" mv $file $f2 done cd ../.. else echo "${path} does not exist, continuing" fi done done