I have JPG files numbered 3006-3057 that I would like to reverse number. I would be content renaming them by adding a backwards number count to the beginning of the name: img_3006.jpg > 99_img_3006.jpg and img_3057.jpg > 48_img_3057.jpg.
+1
A:
basenumber=9999
for file in *.jpg
do
base="${file%.*}"
filenumber="${base#*_}"
mv "$file" "$((basenumber-filenumber))_$file"
done
Ignacio Vazquez-Abrams
2010-05-08 21:26:21
Thanks for the idea. Any thoughts on getting this to work:for i in $(ls *JPG); do echo "4000 - `echo $i | grep -o [0-9]*`" | bc ; done
Donnied
2010-05-08 21:40:58
The script above renames all the files 9999. The cognitive block I'm having is thinking of the script that doesn't number down all the way for each file. The seems like it should be a five minute hack but I'm just seeing popping items on a stack.
Donnied
2010-05-08 21:44:11
The script will fail if there's more than one `_` or if there isn't a number between the `_` and the `.`. The first can be fixed by replacing the `#` in line 5 with `##`. The second, well, that can't be fixed.
Ignacio Vazquez-Abrams
2010-05-08 21:55:31
Once I removed leading identification from the file names things worked fine.for i in *JPG; do mv $i `echo $i|grep -o '[0-9]*.JPG'`; done
Donnied
2010-05-08 21:56:39