Hi,
I've got files with names like this :
[Various-PC3]_Some_Name_178_HD_[e2813be1].mp4
[TTB]_Some_Name_-_496_Vost_SD_(720x400_XviD_MP3).avi
Goffytofansub_Some name 483_HD.avi
And iam trying to rename it with a regular pattern. My gola is this :
Ep 178.mp4
Ep 496.avi
Ep 483.avi
I've tried using sed with substitution expressions :
for f in `ls`
do
OLD=$f
NEW=$(echo $f | sed 's/.*\([0-9]\{3\}\).*\.\(.*\)/Ep \1.\2/1')
echo -n "$OLD => $NEW (o/n) "
read YES_NO
[[ $YES_NO == "y" ]] && mv $OLD $NEW
done
the result is
Ep 813.mp4
Ep 400.avi
Ep 483.avi
One file correctly renamed :-/
This one :
echo $f | sed 's/[^0-9]*\([0-9]\{3\}\).*\.\(.*\)/Ep \1.\2/1'
Went wrong with the first one
[Various-PC3Ep 178.mp4
Ep 496.avi
Ep 483.avi
Then I tried perl. But considering that I have very few knowledges in it, I spent many time on my script
open(LS, "ls -1 |");
foreach (<LS>)
{
$old = $_;
$new = s/(?![0-9]{3})*([0-9]{3}).*\.(.*)/Ep $1.$2/;
print "$old => $new (o/n) ";
chomp($yes_no = <STDIN>);
next unless ( $yes_no == "y");
system("mv $old $new");
} #foreach
for an unexpected result :
Ep 418.mp4
=> 1 (o/n) <- waiting here for input
I've also tried some alternatives of the beginning :
foreach(`ls`)
result
Ep 418.mp4
=> 1 (o/n) <- waiting here for input
This one :
foreach (system("ls -1"))
gave me
Various-PC3]_Some_Name_178_HD_[e2813be1].mp4
[TTB]_Some_Name_-_496_Vost_SD_(720x400_XviD_MP3).avi
Goffytofansub_Some name 483_HD.avi
0 => (o/n) <- waiting here for input
Any idea on how to reach my goal ?
Thx in advance !