Quote:
Originally Posted by atiman
original file name
Code:
20081_dinnerparty01.jpg.jpg
20091_pool01.jpg.jpg
20073_homegame.jpg.jpg
20068_uniday.jpg.jpg
new file name
Code:
dinnerparty01.jpg
pool01.jpg
homegame.jpg
uniday.jpg
|
This should do the trick:
Code:
#!/bin/sh
if [ ! -d ${1} ]; then
printf "$(basename ${0}): Error: parameter needs to be a valid path.\n"
exit 1
else
for img in $(find ${1} -type f -name '*.jpg') ; do
dir=$(dirname ${img})
f=$(basename ${img})
mv ${img} ${dir}/$(printf ${f} | cut -f2- -d_ | sed 's/\.jpg//g').jpg
done
fi
The above script grabs everything in the string after the first underscore (of the filename) and strips away redundant .jpg's at the end of what's left. It only takes the path where you keep your images as an argument. I don't have access to a shell right now so I can't test it for typo's, but it should work, I hope.