Replacing a image filename with a regex pattern in a script
I have a image gallery where files are named in the format img_yyyymmdd_nnn_widthxheight.jpg, for example: img_19981117_001_320x240.jpg
I've written a script that creates a list of all the images in a file. But I need to replace the filename of the image with a regex pattern so it applies to same image with a diffrent size. (Since different sizes of the image have different filename).
How can I replace the image filename (img_19981117_001_320x240.jpg) with a regex pattern of the filename like: /^img_19981117_001_[0-9]*x[0-9]*\.jpg$/ using sed or awk?
#!/bin/sh
DIR="$1"
if [ "$DIR" = "" ] ; then
echo "ERROR: You need to specify dir."
exit -1;
fi
for a in `ls $DIR`
do
if [ ! -f "${DIR}/${a}/IMAGEDESC" ] ; then
echo "Creating IMAGEDESC in ${DIR}/${a}";
for b in `ls $DIR/$a/thumb`
do
echo "/${b}/ No Description" >> "${DIR}/${a}/IMAGEDESC"
done;
fi
done;
exit 0;
|