Fixing wget file names in bash
I downloaded a bunch of images using wget.
The original file names were the same 6 names from 40 different pages. wget names those like this:
01_resize.jpg
01_resize.jpg.1
01_resize.jpg.2
etc.
The other files were:
02_resize.jpg
03_resize.jpg
etc, up to 6.
Here is what I came up with that gives each file a unique name and a valid extension ( 01_resize.jpg.02 becomes 02_01_resize.jpg ) (you can yell at me for parsing the output of ‘ls’ later)
for i in * ; do
seq=$(echo $i | cut -d. -f 3)
fname=$(echo $i | cut -d. -f 1-2)
mv $i $seq\_$fname
done
Hopefully it’s of some use to someone! I’m basically grabbing the different parts of the filename using cut with a delimiter of ‘.’ ; that’s where the magic is. There’s probably a more efficient way of doing this, but it’s what made sense to my brain after being up for 24 hours.





