Rename file extension to lower case

I have been too lazy to write this but today I was finally bothered enough. I don’t pipe it to sh inside awk because you may want to check what it will do before you actually do it.

#!/usr/bin/awk -f

# Usage: ls -1 | lowercase.awk | sh

match($0, /\.[[:upper:]]+$/) {
        if (RSTART == 1)
                next
        name = substr($0, 1, RSTART-1)
        ext = substr($0, RSTART, RLENGTH)
        printf("mv \"%s%s\" \"%s%s\"\n", name, ext, name, tolower(ext))
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s