Odexios
August 18th, 2012, 09:16 PM
Hello everyone!
I have a folder with a few files I want to rename; to speed things up a little I wrote a very little script to parse each file's name and create the new filename.
Here it is:
#! /bin/bash
for file in Sam*.mkv
do
episode="${file#*-}"
episode="${episode%%-*}"
title="${file#*$episode-}"
title="${title%(anime*}"
title="$(echo $title | sed 's/\([Aabcdefghijklmnopqrstuvwxyz.,]\)\([ABCDEFGHIJKLMNOPQRSTUVWXYZ]\)/\1 \2/g')"
echo "$file -> $prefix - $season""x""$episode - $title"".""$extension"
mv "$file" "$prefix - $season""x""$episode - $title"".""$extension"
done
(By the way, I'd appreciate any suggestion for the sed part, which is *really* ugly)
season, extension and episode are variables I defined elsewhere.
Anyway, up to the echo part everything works fine (the new filename I want is right, and so on); but when we get to the line with mv, it raises an error saying that it can't move the file because there is no such file or directory.
I could have expected something went wrong in the parsing phase, but mv should work fine, considering I give it only two strings and the "file" variable remains untouched for all the script; can anyone help me find where's the mistake?
EDIT:
What sed does here:
Whenever it finds a capital letter after a lowercase one (or a capital A, which was the only exception I needed) it puts a space between the capital letter and the previous one (somethingLikeThis -> something Like This).
Filename example:
SamuraiChamploo-12-TheDisorderDiaries(anime-mx)[18D45AB5].mkv
Echo output:
SamuraiChamploo-12-TheDisorderDiaries(anime-mx)[18D45AB5].mkv -> [DivX - ENG/JAP] Samurai Champloo - 01x12 - The Disorder Diaries.mkv
No judgement on the files, please xD
I have a folder with a few files I want to rename; to speed things up a little I wrote a very little script to parse each file's name and create the new filename.
Here it is:
#! /bin/bash
for file in Sam*.mkv
do
episode="${file#*-}"
episode="${episode%%-*}"
title="${file#*$episode-}"
title="${title%(anime*}"
title="$(echo $title | sed 's/\([Aabcdefghijklmnopqrstuvwxyz.,]\)\([ABCDEFGHIJKLMNOPQRSTUVWXYZ]\)/\1 \2/g')"
echo "$file -> $prefix - $season""x""$episode - $title"".""$extension"
mv "$file" "$prefix - $season""x""$episode - $title"".""$extension"
done
(By the way, I'd appreciate any suggestion for the sed part, which is *really* ugly)
season, extension and episode are variables I defined elsewhere.
Anyway, up to the echo part everything works fine (the new filename I want is right, and so on); but when we get to the line with mv, it raises an error saying that it can't move the file because there is no such file or directory.
I could have expected something went wrong in the parsing phase, but mv should work fine, considering I give it only two strings and the "file" variable remains untouched for all the script; can anyone help me find where's the mistake?
EDIT:
What sed does here:
Whenever it finds a capital letter after a lowercase one (or a capital A, which was the only exception I needed) it puts a space between the capital letter and the previous one (somethingLikeThis -> something Like This).
Filename example:
SamuraiChamploo-12-TheDisorderDiaries(anime-mx)[18D45AB5].mkv
Echo output:
SamuraiChamploo-12-TheDisorderDiaries(anime-mx)[18D45AB5].mkv -> [DivX - ENG/JAP] Samurai Champloo - 01x12 - The Disorder Diaries.mkv
No judgement on the files, please xD