Yes, it's csh, should be sh. Run in order, it fixes the 200* entries, then the 199* entries. foreach dir ( `find . -type d | egrep "adsl.archive.0[0-9]{3}"` ) mv $dir `echo $dir | sed 's#adsl.archive.\([0-9][0-9]\)\([0-9][0-9]\)#adsl.archive.20\1_\2#'` end foreach dir ( `find . -type d | egrep 'adsl.archive.[0-9]{4}$'` ) mv $dir `echo $dir | sed 's#adsl.archive.\([0-9][0-9]\)\([0-9][0-9]\)#adsl.archive.19\1_\2#'` end