Article View: comp.unix.shell
Article #63Re: Need script (awk/sed/...) to remove dashes and do initial caps
From: Mark Burhans
Date: Wed, 04 Nov 1992 00:09
Date: Wed, 04 Nov 1992 00:09
52 lines
2573 bytes
2573 bytes
In article <Bx5t40.5DB@unx.sas.com>, sasmob@chewy.unx.sas.com (Mark Burhans) writes:
|>
|> In article <1992Nov2.195646.27860@spectrum.xerox.com>, kris@xerox.com (Kris Schneider) writes:
|> |> Here are some examples of what needs to be done:
|> |>
|> |> hello-world => HelloWorld
|> |> helloworld => Helloworld
|> |> HELLOWORLD => Helloworld
|> |> HELLO-WORLD => HelloWorld
|> |>
|>
|> ----Cut Here----
|> {
|> for( f=1; f<=NF; f++ )
|> {
|> # 1. Make first character Upper Case.
|> # 2. Make rest of the word Lower Case.
|>
|> sub( substr($f,1,1), toupper( substr( $f, 1, 1)), $f );
|> sub( substr($f,2), tolower( substr($f,2)), $f );
|>
|> # If a '-' is found, get rid of it and make the next
|> # character Upper Case.
|>
|> while( (i=index( $f, "-" )) != 0 )
|> {
|> pattern = substr( $f, i, 2 );
|> sub( pattern, toupper(substr($f,i+1,1)), $f);
|> }
|>
|> # Output what you have.
|>
|> print $f <------------+
|> } |
<----------------------------------------~----------+
|> } | |
|> ----Cut Here---- | |
| |
| |
Actually, it would have been better to put this --+ here --+ as a
"print $0"... anyway...
I liked the perl one by Randal (merlyn@ora.com) a lot! That's what
prompted me to changed the "print $f".
Tryin' to keep up with those Perl Maniacs... er... Hackers... :-)
--
---Mark C. Burhans---sasmob@chewy.unx.sas.com---919/677-8001 ext 7324
SAS Institute, Inc., USA, SAS Campus Drive, Cary, NC 27513.
"I'm convinced that Chopin too would dig samba if he had a chance to
groove." -- Basia
Technical Details
Message-ID:
<Bx60G4.CpA@unx.sas.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!emory!gatech!concert!sas!mozart.unx.sas.com!sasmobReferences:
<1992Nov2.195646.27860@spectrum.xerox.com> <Bx5t40.5DB@unx.sas.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!emory!gatech!concert!sas!mozart.unx.sas.com!sasmob From: sasmob@chewy.unx.sas.com (Mark Burhans) Newsgroups: comp.unix.shell,comp.lang.misc Subject: Re: Need script (awk/sed/...) to remove dashes and do initial caps Message-ID: <Bx60G4.CpA@unx.sas.com> Date: 4 Nov 92 00:09:40 GMT Article-I.D.: unx.Bx60G4.CpA References: <1992Nov2.195646.27860@spectrum.xerox.com> <Bx5t40.5DB@unx.sas.com> Sender: news@unx.sas.com (Noter of Newsworthy Events) Organization: SAS Institute Inc. Lines: 52 Originator: sasmob@chewy.unx.sas.com Nntp-Posting-Host: chewy.unx.sas.com