3

I have a collection of files with names like these:

Ace of Aces (Europe).mp4
Action Fighter (USA, Europe) (v1.2).mp4
Addams Family, The (Europe).mp4
Aerial Assault (USA).mp4
After Burner (World).mp4
Air Rescue (Europe).mp4
Aladdin (Europe).mp4
Alex Kidd - High-Tech World (USA, Europe).mp4
Alex Kidd in Miracle World (USA, Europe) (v1.1).mp4
Alex Kidd in Shinobi World (USA, Europe).mp4
Alex Kidd - The Lost Stars (World).mp4
Alf (USA).mp4
Alien 3 (Europe).mp4
Alien Storm (Europe).mp4
Alien Syndrome (USA, Europe).mp4
Altered Beast (USA, Europe).mp4
American Baseball (Europe).mp4
American Pro Football (Europe).mp4
Andre Agassi Tennis (Europe).mp4
Arcade Smash Hits (Europe).mp4
Assault City (Europe) (Light Phaser).mp4

(I have these filenames listed in a text file.) 

I have to get away from parentheses, so I would like to rename the files to remove the parentheses and the text between them, so the filenames will be as follows:

Ace of Aces.mp4
Action Fighter.mp4
Addams Family, The.mp4
Aerial Assaul.mp4
After Burner.mp4
Air Rescue.mp4
Aladdi.mp4
Alex Kidd - High-Tech World.mp4
Alex Kidd in Miracle World.mp4
Alex Kidd in Shinobi World.mp4
Alex Kidd - The Lost Stars.mp4
Alf.mp4
Alien 3.mp4
Alien Storm.mp4
Alien Syndrome.mp4
Altered Beast.mp4
American Baseball.mp4
American Pro Footbal.mp4
Andre Agassi Tennis.mp4
Arcade Smash Hits.mp4
Assault City.mp4

Ideally, any solution should alert me if I have, for example, files like Aladdin (Europe).mp4 and Aladdin (Asia).mp4,  or Ghostbusters (1984).mp4 and Ghostbusters (2016).mp4, and not destroy any files.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
tommy
  • 43

2 Answers2

6

Using Perl's rename commandline:

Use this :

rename 's/\s*\([^\)]+\)//g' *.mp4

Remove -n (aka dry-run) when the output looks satisfactory.

5

With zsh, (also checks for conflicts):

autoload zmv # best in ~/.zshrc
zmv -n '*' '${f//[[:space:]]#[(]*[)]}'

Remove -n or replace with -v when happy.

With //, we remove all occurrences of (...), but since the * is greedy, there will only be at most one match anyway. On 1 (2) 3 (4), it would match " (2) 3 (4)". You can make the * non-greedy by using the S parameter expansion flag:

zmv -n '*' '${(S)f//[[:space:]]#[(]*[)]}'

Or replace * with [^)]# (0 or more non-)s).