Given the awk code from this accepted answer:
awk '
BEGIN{
num=split("a the to at in on with and but or",array," ")
for(i=1;i<=num;i++){
smallLetters[array[i]]
}
}
/TITLE/{
for(i=2;i<=NF;i++){
if(tolower($i) in smallLetters){
$i=tolower(substr($i,1,1)) substr($i,2)
}
else{
if($i~/^"/){
$i=substr($i,1,1) toupper(substr($i,2,1)) substr($i,3)
}
else{
$i=toupper(substr($i,1,1)) substr($i,2)
}
}
}
}
1
' Input_file
This code properly capitalice the lines of a file when it matches some text, in this case TITLE
. The idea is to use it to modify some cue sheet files and properly capitalice them following three basic rules:
- Capitalize all words, with exception to:
- Lowercase all articles (a, the), prepositions (to, at, in, with), and coordinating conjunctions (and, but, or)
- Capitalize the first and last word in a title, regardless of part of speech
Well, I would like to modify the awk code, to add a second array with a list of words to exclude, and always write them as they're written in the matrix.
This would be very useful for words like: McCartney, feat., vs., CD, USA, NYC, etc. Because, without this exclusion array, they would be changed to: Mccartney, Feat., Cd, Usa, Nyc, etc.
This exclusion should be even when these words are the first and last word of the TITLE, as explained in the related question.
For example, with an array like this: "McCartney feat. vs. CD USA NYC"
the code must convert this:
FILE "Two The Beatles Songs.wav" WAVE
TRACK 01 AUDIO
TITLE "dig A pony, Feat. paul mccartney"
PERFORMER "The Beatles"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "From Me to You"
PERFORMER "The Beatles"
INDEX 01 03:58:02
Into this:
FILE "Two The Beatles Songs.wav" WAVE
TRACK 01 AUDIO
TITLE "Dig a Pony, feat. Paul McCartney"
PERFORMER "The Beatles"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "From Me to You"
PERFORMER "The Beatles"
INDEX 01 03:58:02
Instead of doing this:
FILE "Two The Beatles Songs.wav" WAVE
TRACK 01 AUDIO
TITLE "Dig a Pony, Feat. Paul Mccartney"
PERFORMER "The Beatles"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "From Me to You"
PERFORMER "The Beatles"
INDEX 01 03:58:02
Thank you.
See Question&Answers more detail:
os