Article View: comp.unix.shell
Article #61Re: Need script (awk/sed/...) to remove dashes and do initial caps
From: Mark Burhans
Date: Tue, 03 Nov 1992 21:31
Date: Tue, 03 Nov 1992 21:31
57 lines
2341 bytes
2341 bytes
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
|>
|> In other words, the first charatcer should be capitalized, any character
|> following a dash should be capitalized, all others should be lower case, and
|> all dashes should be removed. I have an awk script that will grab the "field"
|> I need, but I'm stuck from there. Any help you can provide is greatly
|> appreciated. Thanks in advance...
|>
Kris,
Here is an awk script that seems to work for me:
----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----
If you save it as dash2cap.awk, then you'd use it as:
awk -f dash2cap.awk InputFileName >OutputFileName
where you supply the InputFileName and the OutputFilename.
Nice 'awking' to you! heheheheh
--
---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:
<Bx5t40.5DB@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>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: <Bx5t40.5DB@unx.sas.com> Date: 3 Nov 92 21:31:12 GMT Article-I.D.: unx.Bx5t40.5DB References: <1992Nov2.195646.27860@spectrum.xerox.com> Sender: news@unx.sas.com (Noter of Newsworthy Events) Organization: SAS Institute Inc. Lines: 57 Originator: sasmob@chewy.unx.sas.com Nntp-Posting-Host: chewy.unx.sas.com