Bash: How do I batch rename series episodes from 1x01* to S01E01* pattern?
I found this answer, but I am rather lost in how to modify it to my case.
Bash: How do I batch rename series episodes from 1x01* to S01E01* pattern?
I found this answer, but I am rather lost in how to modify it to my case.
Bash substrings will do:
for i in ?x??*
do
mv "$i" "S0${i:0:1}E${i:2:2}${i:4}"
done
One approach, using the rename command. Drop the -n when happy with proposed renames.
Explanation:
s/ = substitute(\d+) = match 1 or more digits (season)x = match the "x" character(\d+) = match 1 or more digits (episode)/ = end of search string, start of substitute stringS0 = insert text "S0"$1 = insert the first matched digits from earlier (season)E = insert the "E" character$2 = insert the second matched digits from earlier (episode)/ = end of substitute string-
rename -n -e 's/(\d+)x(\d+)/S0$1E$2/' *
rename(Breaking_Bad_1x01.mkv, Breaking_Bad_S01E01.mkv)
rename(Shameless_3x05.mp4, Shameless_S03E05.mp4)
You may do it one by one:
for f in 1x01*; do
n=`echo $f | sed 's/^1x01/S01E01/'`
mv $f $n
done
1x to S01E, so for f in 1x* ; do echo mv "$f" "${f/1x/S01E}" ; done check that it looks OK, then remove the echo.
– icarus
Dec 05 '16 at 22:23