0

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.

1

3 Answers 3

2

Bash substrings will do:

for i in ?x??*
do
  mv "$i" "S0${i:0:1}E${i:2:2}${i:4}"
done
0
1

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 string
  • S0 = 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)
0
-3

You may do it one by one:

for f in 1x01*; do
    n=`echo $f | sed 's/^1x01/S01E01/'`
    mv $f $n
done
2
  • 1
    This only handles the one episode, not other files named by a similar pattern.
    – Wildcard
    Commented Dec 5, 2016 at 22:19
  • 1
    You want to change 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
    Commented Dec 5, 2016 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .