You are not logged in.
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
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
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
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
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...
pic from 1993, new guitar day.
Offline
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 *
Offline
disregard.
Last edited by hevidevi (2021-11-09 14:01:50)
Offline
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)
Brianna Ghey — Rest In Power
Offline
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.
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
Just an fyi on renaming large numbers of files. sed works really well.
Offline