0

I have thousands of really old video files that have brackets of all types strewn in them in no particular order. I'm trying to "clean" them, that is, rename these files so that all the brackets and the strings in them are eliminated, effectively replaced by an empty string. An example would be something like

{xyz}<abc>actual_title[prev_suffix](suffix)some_other_text.mp4

The brackets are used correctly, that is, there are no filenames like {xyz<}abc>, though they can be nested brackets. There are no files that are named entirely in brackets; there is always a section that is un-bracketed. It is also possible that once all the brackets are removed two files will have the exact same name, in which case I don't really care how they are differentiated.

The result I'd like would be

actual_titlesome_other_text.mp4

Naively this is easy to do by doing multiple passes on the filename, one pass for each bracket pair, but is it possible to do this quicker, possibly by constructing a regex?

  • Advice to newcomers: If an answer solves your problem, please accept it by clicking the large check mark (✓) next to it and optionally also up-vote it (up-voting requires at least 15 reputation points). If you found other answers helpful, please up-vote them. Accepting and up-voting helps future readers. – Gilles Quénot Jan 22 '23 at 07:14

1 Answers1

0

Using Perl's rename:

rename -n 's/\{[^\}]+\}//g;s/<[^<]+>//g;s/\[[^\]]+\]//g;s/\([^\)]+\)//g' ./*actual*

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