ask Dr LJ

Jan. 10th, 2009 08:57 am
gsh: (Default)
[personal profile] gsh
I have several hundred files that have been retrieved from a content mangagement
system that munged the filenames.The files are all named Rendition-XX_orig_file.name
I'm sure there is a two line perl or other scripty language that can
rename the files back to orig_file.name, but I'm not enough of a perl hacker
to figure it out. Does anyone have a sugguestion that would cause me
to worship your sheer geek foo?

Date: 2009-01-10 02:18 pm (UTC)
wotw: (Default)
From: [personal profile] wotw
As a non-perl-hacker, here's what I would do.

First

"ls -l Rendition* > foo"

Then

"cut -b55-80 foo>foo2"

(adjusting the 55-80 range as needed so you get a list of all your
file names)

Then edit foo2, replacing "Rendition-XX_" with "doit "

Then create an executable file called "doit" that reads

"mv Rendition-XX_%1 %1"

Then make foo2 executable, and execute it.


Date: 2009-01-10 02:22 pm (UTC)
wotw: (Default)
From: [personal profile] wotw
Except that because this is unix, I'd use $1 instead
of %1. Sorry.

Date: 2009-01-10 03:40 pm (UTC)
geekchick: (Default)
From: [personal profile] geekchick
Are they all in the same directory? You could try something like this (assuming that the "XX" are digits):

ls * | perl -ne 'chomp; next unless -e; $old = $_; s/Rendition-\d+_//; next if -e; rename $old, $_;'

I'm pretty rusty and I'm sure there's a better way to do it, but I think that should work. May want to test it on a copy of some of the files first. =)
Edited Date: 2009-01-10 03:41 pm (UTC)

June 2015

S M T W T F S
 123456
78 910111213
14151617181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 25th, 2026 07:01 pm
Powered by Dreamwidth Studios