NetAdminTools.com
 
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Converting File Extension to Lower Case With Perl
Topic: Perl   Posted:2006-09-04
Printer Friendly: Print

spacerspacer
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).




Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com