#!/bin/sh
# capitalize first letter of all items in current directory:
ls -1 | awk '
## This script gets run once for each line of output from the "ls -1" command.
{
space = " " ## a space character
dquote = "\"" ## a double-quote character
backslash = "\\" ## a backslash character
## Each line of input ($0) is a new file name to convert:
old_name = $0
## Insert backslashes in front of any " characters inside the file name,
## so that they are preserved when we later invoke system() on it:
gsub(dquote, backslash dquote, old_name)
## Copy old_name to new_name, and capitalize first letters of all words:
in_word = 0
new_name = ""
for (i = 1; i <= length(old_name); ++i) {
tail = substr(old_name,i)
c = substr(tail,1,1)
if (tail != ".mp3" && tail != ".avi") {
if (c !~ "[a-zA-Z]") {
in_word = 0
} else if (in_word == 0) {
in_word = 1
c = toupper(c)
}
}
new_name = new_name c
}
## If new_name differs from old_name, then rename the file:
if (new_name != old_name) {
## Issue a command to rename the file:
rename = "/bin/mv"
print rename space dquote old_name dquote space dquote new_name dquote
system(rename space dquote old_name dquote space dquote new_name dquote)
}
}'