| Ed Morton 2005-04-26, 5:56 pm |
|
Michael Heiming wrote:
> In comp.unix.shell Ed Morton <morton@lsupcaemnt.com>:
<snip>
>
>
>
>
>
>
>
>
> vi file 2>/dev/null << EOF
> :%s/\<\(.\)\([^ ]*\)/\u\1\L\2/g
> :wq!
> EOF
>
>
> Should do the trick.
>
But that isn't actually any shorter than the awk solution:
vim file 2>/dev/null << EOF^J:%s/\<\(.\)\([^ ]*\)/\u\1\L\2/g^J:wq!EOF
awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1' file
It also modifies the original file, which may or may not be what the OP
wants. If it is what he wants, the vim solution's shorter since the awk
one would require a tmp file or more code, but if it isn't then the vim
solutions longer since the vim solution would require a tmp file plus a
cat of the result.
It does have the benefit over the awk solution that it preserves
white-space so it's definitely a solution I plan to remember.
I guess as with so many things in UNIX, there's no silver bullet but
many choices of metals and forging tools ;-).
Thanks,
Ed.
|