🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #64

Re: Need script (awk/sed/...) to remove dashes and do initial caps

#64
From: Tom Christiansen
Date: Wed, 04 Nov 1992 00:46
36 lines
2296 bytes
From the keyboard of kris.wbst129@xerox.com:
: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...
:
:FWIW, this is to help a porting effort from Lisp to C.  Lisp was set up to
:treat everything as a capital, so this was really a non-issue.  C, at least to
:my knowledge, is a bit less flexible in this regard.

Actually, C is more flexible, because it distinguishes case.

    #!/usr/bin/perl -p
    s/(\w+)/\L$1/g;		# all idents to all lower
    s/-(\w)/\u$1/g;		# -x to X
    # s/-(\w)/_\u$1/g;		# -x to _X
    # s/-(\w)/_$1/g;		# -x to _x
    s/^\(\w)/\u$1/;		# leading x to X

I've commented out a couple lines to show you other things I might
do.  I would prefer 'HELLO-WORLD' to simply  be 'hello_world'.

--tom
-- 
    Tom Christiansen      tchrist@convex.com      convex!tchrist

    "UNIX was not designed to stop you from doing stupid things, because
     that would also stop you from doing clever things." -- Doug Gwyn
Technical Details
Message-ID: <1992Nov4.004616.20122@news.eng.convex.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!emory!sol.ctr.columbia.edu!eff!news.oc.com!convex!tchrist
References: <1992Nov2.195646.27860@spectrum.xerox.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!emory!sol.ctr.columbia.edu!eff!news.oc.com!convex!tchrist
From: tchrist@convex.COM (Tom Christiansen)
Newsgroups: comp.unix.shell,comp.lang.misc
Subject: Re: Need script (awk/sed/...) to remove dashes and do initial caps
Message-ID: <1992Nov4.004616.20122@news.eng.convex.com>
Date: 4 Nov 92 00:46:16 GMT
Article-I.D.: news.1992Nov4.004616.20122
References: <1992Nov2.195646.27860@spectrum.xerox.com>
Sender: usenet@news.eng.convex.com (news access account)
Reply-To: tchrist@convex.COM (Tom Christiansen)
Organization: Convex Computer Corporation, Colorado Springs, CO
Lines: 36
Originator: tchrist@pixel.convex.com
Nntp-Posting-Host: pixel.convex.com
X-Disclaimer: This message was written by a user at CONVEX Computer
              Corp. The opinions expressed are those of the user and
              not necessarily those of CONVEX.