Print Logo

Converting File Extension to Lower Case With Perl




<<  <   >  >>

Let's say that you have a bunch of references to files that take the format IMGblahx.JPG, but all of the files are actually IMGblahx.jpg. An example file would be named IMG_1807.JPG. To change all of the references to IMGblahx.JPG to IMGblahx.jpg, use this one line perl script:

$ perl -pi -e "s|(IMG......)JPG|\$1jpg|g" *

Put an escape in to make it really match a dot before JPG if you want. It was close enough for us to fix IMG, and to be doubly sure we matched six characters exactly before JPG, and, yeah, we could have used a repeat for dot as well, but this is something that works, and is easy to remember. Notice that we have to escape the $ on this shell (BASH).



This article comes from NetAdminTools:
http://www.netadmintools.com/

The URL for this story is:
http://www.netadmintools.com/art567.html

Copyright 1997-2009 NetAdminTools.com. Read our Terms of Use.