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.

1
2
3
4
5
6
7
8
9
10
11
#!/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))
}