The officially official Devuan Forum!

You are not logged in.

#1 2021-11-07 20:47:21

rolfie
Member
Registered: 2017-11-25
Posts: 587  

[SOLVED] Delete track number from music file names

Got a lot of music data on my file server. Before finding out that an easy duplicate recognition isn't possible, files were ripped beginning with the track number from the CD. I stopped this later on and want to clean up now. Example:

01 - Canned Heat - On The Road Again.wav

My goal is to remove the track number from the file name for all files having this in the current directory. Example:

Canned Heat - On The Road Again.wav

From digging through man pages and several threads on many forums, I finally came up with this approach:

find . -type f -name '[0-9][0-9] - *' -exec rename 's/^[0-9][0-9] - //' {} +

The find part works, with the -print option it lists all the files in the test directory I have set up. The rename part has a problem, and I can't figure out what's wrong. I have learned that compared to Debian the rename utility isn't part of the util-linux package but a perl application that has to be installed separately. How is the relation between regex and a perl-expression?

In any case, above line in a script does not seem to do anything, the script terminates without action, output or error. What ido I need to change?

rolfie

Offline

#2 2021-11-07 20:58:03

hemimaniac
Member
Registered: 2020-02-04
Posts: 5  

Re: [SOLVED] Delete track number from music file names

would this work for ya?

http://www.guyrutenberg.com/2009/01/12/ … using-sed/

Or if you would like a GUI , I use gprename all the time, with gprename you may need to also install ssed as for some reason it doesn't get pulled automatically

Last edited by hemimaniac (2021-11-07 21:09:35)

Offline

#3 2021-11-07 21:25:41

rolfie
Member
Registered: 2017-11-25
Posts: 587  

Re: [SOLVED] Delete track number from music file names

One step further, replaced rename with file-rename from the Debian package rename. It now reads

find . -type f -name '[0-9][0-9] - *' -exec file-rename -v 's/^[0-9][0-9]\s-\s//' {} +

A direct

file-rename -v 's/^[0-9][0-9]\s-\s//' '01 - Canned Heat - On The Road Again.wav'

renames the file as desired. So I have a problem with the hand-over of the filenames from find to file-rename. And here I am stuck. I have too little insight into this topic.

rolfie

Offline

#4 2021-11-07 21:32:10

rolfie
Member
Registered: 2017-11-25
Posts: 587  

Re: [SOLVED] Delete track number from music file names

hemimaniac wrote:

would this work for ya?

http://www.guyrutenberg.com/2009/01/12/ … using-sed/

Or if you would like a GUI , I use gprename all the time, with gprename you may need to also install ssed as for some reason it doesn't get pulled automatically

Well, different approach. I first want to try if I can get my approach to work. Thank you anyway.

rolfie

Offline

#5 2021-11-08 01:53:43

GlennW
Member
Registered: 2019-07-18
Posts: 169  

Re: [SOLVED] Delete track number from music file names

I'm interested in your command line approach. I use easytag to change mine, but it's one at a time and can be quite arduous. Following...

Offline

#6 2021-11-08 03:16:57

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 632  

Re: [SOLVED] Delete track number from music file names

The -exec option variant for find that ends with ';' rather than + lets you use {} more freely, and then perhaps the following would work

find . -type f -name '[0-9][0-9] - *' \
    -exec sh -c "file-rename -v 's/^[0-9][0-9]\s-\s//' '{}'" ';'

or almost certainly (and with less python):

find . -type f -name '[0-9][0-9] - *' \
    -exec sh -c 'X="{}"; mv "{}" "${X#*- }"' ';'

EDIT: added the missing *

Online

#7 2021-11-08 10:23:29

hevidevi
Member
Registered: 2021-09-17
Posts: 68  

Re: [SOLVED] Delete track number from music file names

disregard.

Last edited by hevidevi (2021-11-09 14:01:50)

Offline

#8 2021-11-08 14:47:23

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 1,873  
Website

Re: [SOLVED] Delete track number from music file names

I would use

for file in * ; do mv "$file" "${file#*- }" ; done

EDIT: see section 2.6.2 of the POSIX sh command language guide for an explanation.

Last edited by Head_on_a_Stick (2021-11-08 15:09:49)


antifa ftw!

Offline

#9 2021-11-09 18:44:43

rolfie
Member
Registered: 2017-11-25
Posts: 587  

Re: [SOLVED] Delete track number from music file names

ralph.ronnquist wrote:

The -exec option variant for find that ends with ';' rather than + lets you use {} more freely, and then perhaps the following would work

find . -type f -name '[0-9][0-9] - *' \
    -exec sh -c "file-rename -v 's/^[0-9][0-9]\s-\s//' '{}'" ';'

That proposal causes 3 times a: "1: Syntax error: Unterminated quoted string". Tried to fix this, but failed. No idea what exactly caused that to fail. Fiddeled with the quotes around the {}, the ; and the file-rename string.

ralph.ronnquist wrote:

or almost certainly (and with less python):

find . -type f -name '[0-9][0-9] - *' \
    -exec sh -c 'X="{}"; mv "{}" "${X#*- }"' ';'

and this one does the job! Thank you, never would have got that together. This line also works on both ways a ' is quoted in the file names on the terminal line:

"Chris Rea - Let's Dance.wav"
'Dr. Hook & The Medicine Show - Sylvia'\''s Mother.wav'

Again, many thanks for this solution.

rolfie

Offline

#10 2021-11-25 14:48:45

garyk
Member
Registered: 2018-04-14
Posts: 37  

Re: [SOLVED] Delete track number from music file names

Just an fyi on renaming large numbers of files.  sed works really well.

Offline

Board footer