So I have the following shell script for batch renaming the episodes of some given TV series:
#!/bin/bash
#script for renaming files of form "*01*.ext" to "Episode 01.ext";
counter=0
for all_files in * ; do
counter=$(( $counter+1 )) #increments $counter by 1;
#creates counter "number" with two digit format (eg: 01):
if [[ 1 = $(( $counter<10 )) ]] ; then
number=0$counter
else
number=$counter
fi
#checks all file names for presence of $number and renames those files:
for numbered_file in *$number* ; do
ext=${numbered_file##*.}
mv "$numbered_file" "Episode $number.$ext"
done
done
I now want to improve the script to account for some quite common exceptions. In particular I don't want the "20" in "720p" to be interpreted as referring to "Episode 20". What I want then, is a way to refine the *$number* pattern from the inner for loop. (number is a variable assigned to 01, 02, 03 and so forth.)
How do I achieve something along the lines of:
* no "7" here $number no "0" or "p" here *
Please feel free to point out anything else about the above script that is awkwardly done. It is my first attempt at a vaguely useful script and as such it is probably full of stylistic monstrosities. ;-)
findcommand.