Archive

Posts Tagged ‘title case’

Converting a Textified File Name back into Title Case

March 11th, 2010 No comments

This could easily be done with Perl but here is a zsh solution

I want to convert a textified string to a Title Case Phrase
>
> eg
> fred-goat-dog.jpg to Fred Goat Dog
>

% print ${${(Cs:-:):-fred-goat-dog.jpg}%.*}
Fred Goat Dog

This curiously uses a smiley face though
foo=fred-goat-dog.jpg
echo ${(C)foo:gs/-/ /:r} might be more elegant
From the zsh newsgroup (RD&MM)

and to textify a phrase

s=’Fred Goat Dog’
print ${(L)s:gs/ /-/}.jpg
or
print ${(L)s// /-}.jpg

Categories: zsh Tags: , ,