swestrup: (Default)
[personal profile] swestrup
Am 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.

Date: 2009-02-14 08:27 am (UTC)
From: [identity profile] sps.livejournal.com
perl -e 'for (sort {$a<=>$b} <*>) /\(\d+\)\.sthg/ and rename $_, (100+$1).".sthgelse"' ishly?

Date: 2009-02-14 07:53 pm (UTC)
From: [identity profile] joenotcharles.livejournal.com
Why the fetish for doing everything on one line? Put your script in a text file, run the text file, fix mistakes, delete the text file when you're done, or save it somewhere if you think it'll be useful again.

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.

Date: 2009-02-14 08:16 pm (UTC)
From: [identity profile] skjalm.livejournal.com
Agreed! Doing one liners (in whatever language) is fun, but sometimes it's not worth the extra hassle if the point of the exercise is to get something done rather than to do a nifty one liner ;)

That being said I couldn't help myself (see comment below) ;)

January 2017

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 13th, 2026 10:17 pm
Powered by Dreamwidth Studios