Bulk Rename
Feb. 14th, 2009 01:46 amAm I right that there isn't a half-decent bulk rename command out there for Linux? I did a search and found a bunch, but they all rely on regex which is not terribly useful when what you want to do is pull a number out of the middle of a file name, do math on it, and depending on the result replace it with a string containing a different embedded number.
(Okay, maybe this can be done with Perls ultra-extended regular expressions, but after rereading how they work a dozen times, and trying 30 different patterns, I gave up as the documentation is inadequate and I haven't been able to figure out how to express this.)
This, by-the-way is what you want to do if you have 1000 files numbered sequentially, from 10 years of a TV show, and you want to rename them as season and episode numbers, and the number of episodes per season was not a constant...
Okay, I know this is an edge case, but if I were to write a bulk rename, this would be one of the things I would, for certain, want to make easy. Anything less complex and you can just throw together a one-line bash for-loop to handle it.
(Okay, maybe this can be done with Perls ultra-extended regular expressions, but after rereading how they work a dozen times, and trying 30 different patterns, I gave up as the documentation is inadequate and I haven't been able to figure out how to express this.)
This, by-the-way is what you want to do if you have 1000 files numbered sequentially, from 10 years of a TV show, and you want to rename them as season and episode numbers, and the number of episodes per season was not a constant...
Okay, I know this is an edge case, but if I were to write a bulk rename, this would be one of the things I would, for certain, want to make easy. Anything less complex and you can just throw together a one-line bash for-loop to handle it.
no subject
Date: 2009-02-14 08:03 am (UTC)Just how hairy is the mapping you need?
no subject
Date: 2009-02-14 08:18 am (UTC)Just that its on the border between what the command line stuff will handle easily, and what you need to write a script for.
Frankly, its annoying to have to write a script because I have to figure out how to use a few dozen commands and weave them together. Same with bash.
In the end I broke the problem into pieces by first moving each group into its own subdir and then running slightly-modified 1-line commands on each subdir. But frankly, when I write a for loop that passes something in turn through echo, cut, tr, and xargs 'mv', I start thinking there has to be a better way...
(see, I need to process the files in numerical sort order, despite there being a variable number of digits in the numbers...)
no subject
Date: 2009-02-14 08:20 am (UTC)I vaguely recall you mentioning it when you gave it me, but not what it was you said. Should I be wearing lead underwear?
no subject
Date: 2009-02-14 08:27 am (UTC)no subject
Date: 2009-02-14 08:28 am (UTC)no subject
Date: 2009-02-14 08:28 am (UTC)no subject
Date: 2009-02-14 10:22 am (UTC)no subject
Date: 2009-02-14 07:53 pm (UTC)If it's complicated enough that it takes you significant brain power to figure out how to shove it into a one-liner, or to work out the escaping involved, then the extra time taken to write to and delete a text file goes toward saving you from that, and it makes debugging the inevitable mistakes so much easier.
no subject
Date: 2009-02-14 08:16 pm (UTC)That being said I couldn't help myself (see comment below) ;)
no subject
Date: 2009-02-14 08:20 pm (UTC)As mentioned it's not pretty, but does have the advantage, imho, that I could build the mv commands and see that they looked sane before throwing them into a new shell. Plus... it's late so I have apparently made the classic mistake of swapping mod and div in the command *head+desk*
I'll shut up and go to bed now ;)
no subject
Date: 2009-02-14 08:44 pm (UTC)