Perl help

Discuss Programming

Perl help

Postby byrdman » Thu Jul 10, 2003 11:00 am

I was wondering if anyone out there would know how to do the following in perl?
I have multiple images taken from a webcam and need to rename them. There is over 200 images.
Each file is named 'filename1234 (1).jpg","filename1234 (2).jpg" and so on. Does anyone know a way to quickly get rid of the parens so I could get these sequentialy?
your help is greatly appreciated(sp)
Thanks
byrdman
administrator
administrator
 
Posts: 225
Joined: Thu May 08, 2003 1:59 pm
Location: In the cloud

Postby Void Main » Thu Jul 10, 2003 6:53 pm

Well, here's a way to do it from a bash command line:

Code: Select all
for i in *; do mv $i `echo $i | tr -d '(' | tr -d ')'`; done
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby byrdman » Thu Jul 10, 2003 9:16 pm

thanks, void!!
I owe you lunch, that worked!! Once again, you proved you are 'The One.'
byrdman
administrator
administrator
 
Posts: 225
Joined: Thu May 08, 2003 1:59 pm
Location: In the cloud

Postby Void Main » Thu Jul 10, 2003 9:24 pm

byrdman wrote:thanks, void!!
I owe you lunch, that worked!! Once again, you proved you are 'The One.'


Chevy's? ;)

Of course there are a bazillion ways to do what you wanted. Maybe this would be a good thread for everyone to throw in other ways of doing it. Here's another bash way:

Code: Select all
for i in *;do j=${i/(/};mv $i ${j/)/};done


This way should be more efficient because it doesn't require the two system calls to the tr command or the pipeline for every file that gets renamed.
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA

Postby byrdman » Fri Jul 11, 2003 7:27 am

Ok, this is the last attempt of having you solve my perl ignorance with out me looking it up myself. I have another folder with a bunch of webcam pix that need the last 9 characters before the .jpg shaved off. Could you help me with that one?

This --> IMG-CH00-200304031400-3456-544.jpg
Should be -> IMG-CH00-200304031400.jpg
and for extra credit
shaving off the first 9 also to be

200304031400.jpg
byrdman
administrator
administrator
 
Posts: 225
Joined: Thu May 08, 2003 1:59 pm
Location: In the cloud

Postby Void Main » Fri Jul 11, 2003 5:00 pm

Again, one of many ways, certainly not the shortest:

Code: Select all
for i in *;do mv $i `echo $i | sed "s/IMG-CH00-\(............\).*/\1.jpg/"`; done


a little shorter but still using sed:

Code: Select all
for i in *;do mv $i `echo $i | sed "s/.\{9\}\(.\{12\}\).\{9\}/\1/"`; done
User avatar
Void Main
Site Admin
Site Admin
 
Posts: 5705
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron