Originally Posted by
m3_del
All,
I have a directory filled with many subdirectories of tv episodes. I am looking to get to an end state with a simple script that leaves me with the season/episode number of sxxexx. Right now the majority of the files (but not all) are formatted showname - 1x23 - epname.ext. I have a Regex that identifies files that include the numbering pattern. [0-9]*[0-9]x[0-9][0-9] this catches episodes without the 01x01 pattern. I am unsure about how to make this rename to the desired pattern. Any help would be appriciated.
While my way is probably not particularly eloquent, here's what I might do. To rename the following files:
Code:
Chuck.The.Woodpecker.1x56.randomdata
Chuck.The.Woodpecker.1x57.randomdata
etc
From the directory containing the files:
Code:
for f in *
do echo $(echo "$f" | sed 's/Chuck\.The\.Woodpecker\.1x\([0-9][0-9]\)\.randomdata/chuck\.the\.woodpecker\.s01e\1\.newdata/'
done
Which will simply echo what the new file names would be. If you're happy with the new names, then you can simply change the initial echo to a mv:
Code:
for f in *
do mv "$f" $(echo "$f" | sed 's/Chuck\.The\.Woodpecker\.1x\([0-9][0-9]\)\.randomdata/chuck\.the\.woodpecker\.s01e\1\.newdata/')
done
Which gets you:
Code:
chuck.the.woodpecker.s01e56.newdata
chuck.the.woodpecker.s01e57.newdata
etc
Bookmarks