Created
December 26, 2011 04:34
-
-
Save phinze/1520531 to your computer and use it in GitHub Desktop.
Rename sets of files with numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rename a set of files with numbers by adding one | |
# | |
# example renaming a set of files like SC-123A.MUS, SC-123B.MUS, etc. | |
# | |
# move files 165-169 up one to be 166-170, leaving room for a new 165 | |
# ./rename.sh *{165..169}*.MUS | |
# | |
filenames="$@" | |
mkdir renamed | |
# for file in *{170..188}*.MUS | |
for file in $filenames | |
do | |
number_in_file=$(echo -n $file | sed 's/[^0-9]*//g') | |
new_number=$(($number_in_file+1)) | |
new_filename=$(echo $file | sed "s/$number_in_file/$new_number/") | |
echo "mv -v $file renamed/$new_filename" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment