Score:0

How can I rename files by switching the order of strings inside the filenames?

in flag

I think the title is not clear, English is not my first language, sorry. But I hope you get the point with an example. I have a lot of files like this :

(Name of Composer) Title of song - Name of artist.ext

The constants are the parenthesis and the hyphen.

I'd like to rename as Name of artist - Title of song (Name of Composer).ext

I checked the man of rename and examples here and elsewhere on the web but to no avail. Is it possible? Could some bash-guru help me?

Thanks in advance.

Score:4
hr flag

I'd suggest mmv (from the package of the same name) over any of the rename commands for this kind of thing:

$ mmv -n '(*) * - *.*' '#3 - #2 (#1).#4'
(Name of Composer) Title of song - Name of artist.ext -> Name of artist - Title of song (Name of Composer).ext

If you are restricted to using the Perl-based rename, then

$ rename -n 's/^\((.*?)\) (.*?) - (.*?)\.(.*)$/$3 - $2 ($1).$4/' *.*
rename((Name of Composer) Title of song - Name of artist.ext, Name of artist - Title of song (Name of Composer).ext)

In either case remove the -n once you are happy with the proposed transformations.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.