Renaming files in batch
Yesterday I stumbled upon a problem renaming files. I had a really big bunch of files named as [numbers]{abigpileofcharacters}.jpeg/gif. I needed to work with filenames more standarized, something like [numbers].jpeg/gif.
First problem was finding a way to rename those files. I thought of a piped mv command with some sed or something like that, but it got complicated.. so I asked on my favorite IRC channel and a friend told me about a script that comes inside a Debian package when you install XFCE, that script is named prename, it is a modification of an old script named rename. It’s written in perl and its Awesome!
It’s awesome because of this:
perl renamer.pl 's/(\d+).*\.([\w]+)/$1.$2/' *.*
If you dont understand that, go read about Regular expressions. The script renames the files according to the regular expressions using $1 and $2. That’s just awesome.
As the Debian package is not usable in OsX I’ve uploaded to GitHub and BitBucket.
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL
Leave a comment