www.flickr.com

2006-05-18

Writing to the geek roots: Reverse the order of jpg files.

Shopper's Drug Mart has an annoying habit of scanning film in reverse order. The last frame, the most recent frame, is frame #0 and when I copy the photos off the photoCD I want to fix it by reversing the order of the files. Here's how I fix it once and forever.

ls *.jpg | tac | perl -ne 'chomp($_);printf("mv %s %02i_%s\n",$_,$i++,$_)' | sh

Got that? Translated: make a list of jpg files, then reverse the list, then print out commands to rename each file but with a counter prefixed onto the name, then run those commands.

There. No longer a closet unix geek.

2 Comments:

Blogger Derek said...

Perl? I'm surprised you didn't awk it. :)

9:29 a.m.  
Blogger slightly-less-random said...

Actually I did awk it and then chose perl for the blog because I'm not sure how widely accepted "printf" is in awk. Good call on my style. :)

11:20 a.m.  

Post a Comment

<< Home