1
$ dir  
Magi The Labyrinth Of Magic Episode 1 English Dubbed.mp4  
Magi The Labyrinth Of Magic Episode 2 English Dubbed.mp4  
Magi The Labyrinth Of Magic Episode 3 English Dubbed.mp4  
Magi The Labyrinth Of Magic Episode 4 English Dubbed.mp4  
Magi The Labyrinth Of Magic Episode 5 English Dubbed.mp4  
Magi The Labyrinth Of Magic Episode 6 English Dubbed.mp4  
Magi The Labyrinth Of Magic Episode 6 English Dubbed.mp4-1.part 

$ rename -n 's/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ {1..5}.+mp4/MTLOM\ \(DUB\)\ 0*{1..5}.mp4/g' *

Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 1) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 2) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 3) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 4) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 5) line 1.
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/Magi\ The\ Labyrinth\ Of\ Magic\ Episode\ { <-- HERE 1..5}+mp4/ at (eval 6) line 1.

I want to rename some files and not others; out of 30 files, files to be ignored are the sixth 6, 16, 8, 28 and 19.

1 Answer 1

2

To rename all but files 6, 8, 16, 19 and 28 if there are 30 files in total:

$ rename -n 's/Magi The Labyrinth Of Magic Episode ([^68][^689]?|18|26|29) .+mp4/MTLOM (DUB) $1.mp4/g' *
rename(Magi The Labyrinth Of Magic Episode 10 English Dubbed.mp4, MTLOM (DUB) 10.mp4)
rename(Magi The Labyrinth Of Magic Episode 11 English Dubbed.mp4, MTLOM (DUB) 11.mp4)
rename(Magi The Labyrinth Of Magic Episode 12 English Dubbed.mp4, MTLOM (DUB) 12.mp4)
rename(Magi The Labyrinth Of Magic Episode 13 English Dubbed.mp4, MTLOM (DUB) 13.mp4)
rename(Magi The Labyrinth Of Magic Episode 14 English Dubbed.mp4, MTLOM (DUB) 14.mp4)
rename(Magi The Labyrinth Of Magic Episode 15 English Dubbed.mp4, MTLOM (DUB) 15.mp4)
rename(Magi The Labyrinth Of Magic Episode 17 English Dubbed.mp4, MTLOM (DUB) 17.mp4)
rename(Magi The Labyrinth Of Magic Episode 18 English Dubbed.mp4, MTLOM (DUB) 18.mp4)
rename(Magi The Labyrinth Of Magic Episode 1 English Dubbed.mp4, MTLOM (DUB) 1.mp4)
rename(Magi The Labyrinth Of Magic Episode 20 English Dubbed.mp4, MTLOM (DUB) 20.mp4)
rename(Magi The Labyrinth Of Magic Episode 21 English Dubbed.mp4, MTLOM (DUB) 21.mp4)
rename(Magi The Labyrinth Of Magic Episode 22 English Dubbed.mp4, MTLOM (DUB) 22.mp4)
rename(Magi The Labyrinth Of Magic Episode 23 English Dubbed.mp4, MTLOM (DUB) 23.mp4)
rename(Magi The Labyrinth Of Magic Episode 24 English Dubbed.mp4, MTLOM (DUB) 24.mp4)
rename(Magi The Labyrinth Of Magic Episode 25 English Dubbed.mp4, MTLOM (DUB) 25.mp4)
rename(Magi The Labyrinth Of Magic Episode 26 English Dubbed.mp4, MTLOM (DUB) 26.mp4)
rename(Magi The Labyrinth Of Magic Episode 27 English Dubbed.mp4, MTLOM (DUB) 27.mp4)
rename(Magi The Labyrinth Of Magic Episode 29 English Dubbed.mp4, MTLOM (DUB) 29.mp4)
rename(Magi The Labyrinth Of Magic Episode 2 English Dubbed.mp4, MTLOM (DUB) 2.mp4)
rename(Magi The Labyrinth Of Magic Episode 30 English Dubbed.mp4, MTLOM (DUB) 30.mp4)
rename(Magi The Labyrinth Of Magic Episode 3 English Dubbed.mp4, MTLOM (DUB) 3.mp4)
rename(Magi The Labyrinth Of Magic Episode 4 English Dubbed.mp4, MTLOM (DUB) 4.mp4)
rename(Magi The Labyrinth Of Magic Episode 5 English Dubbed.mp4, MTLOM (DUB) 5.mp4)
rename(Magi The Labyrinth Of Magic Episode 7 English Dubbed.mp4, MTLOM (DUB) 7.mp4)
rename(Magi The Labyrinth Of Magic Episode 9 English Dubbed.mp4, MTLOM (DUB) 9.mp4)

Using () to save the pattern and $1 to reference it. I am not sure what you want to happen with the 0* in your replacement - I just took it out. Adjust as desired.

I took out the unnecessary escapes

Note on regex

-[^68][^689]?|18|26|29 match any char but 6 or 8 followed optionally by any char but 6, 8, or 9, or, match 18, or, match 26, or, match 29. Not very elegant...

5
  • edited the answer and by many you can assume there are like 20-30 files for now.
    – devilz
    Dec 11, 2016 at 8:58
  • @devilz edited... how's that? Better if you tell us exactly what you are trying to do, then we can make suitable regex...
    – Zanna
    Dec 11, 2016 at 9:07
  • out of 30 files, files to be ignored are the sixth 6, 16, 8, 28 and 19. The files are getting downloaded and they are not downloading in the proper manner. Takes an approx of 30 min for 5 files to get downloaded but not interested to wait that long.
    – devilz
    Dec 11, 2016 at 9:22
  • thx mate, solved the probs
    – devilz
    Dec 11, 2016 at 10:34
  • @devilz always a pleasure :D
    – Zanna
    Dec 11, 2016 at 10:36

You must log in to answer this question.

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