Renaming files to remove parenthesized strings

Renaming files to remove parenthesized strings



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.


Aladdin (Europe).mp4


Aladdin (Asia).mp4


Ghostbusters (1984).mp4


Ghostbusters (2016).mp4





Are you on a gnu/linux system with the "rename" or "prename" utility?
– Jeff Schaller
Sep 4 '18 at 13:00





Also, are you renaming files, or editing a text file?
– Jeff Schaller
Sep 4 '18 at 13:00





I only need rename files, and yes there is rename.
– tommy
Sep 4 '18 at 13:00





What happens if you have Aladdin (Europe).mp4 and Aladdin (Asia).mp4, for example?
– Jeff Schaller
Sep 4 '18 at 13:03


Aladdin (Europe).mp4


Aladdin (Asia).mp4





it could be a problem because i have to get away all things from parenthesis
– tommy
Sep 4 '18 at 13:04




2 Answers
2



Use this :


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



Should be the perl's rename command, if it's not this one, you can download it with no dependencies from cpan.org



With zsh, (also checks for conflicts):


zsh


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



Remove -n or replace with -v when happy.


-n


-v



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:


//


(...)


*


1 (2) 3 (4)


" (2) 3 (4)"


*


S


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



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


*


[^)]#


)



Thanks for contributing an answer to Unix & Linux Stack Exchange!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)