[comp.unix.questions] Converting to uppercase/lowercase in sed

merlyn@iwarp.intel.com (Randal Schwartz) (08/17/90)

In article <3766@umbc3.UMBC.EDU>, rostamia@umbc5 writes:
| Is there a way to convert characters to uppercase or to lowercase in sed?
| In EX the command
| s/asdf/\U&/
| changes the string asdf to ASDF, but ed and sed do not seem to be as
| sophisticated as ex :-(
| 
| Any ideas?

yeah, the not very well documented "y" command.

	y/a-z/A-Z/

uppercases the pattern space.  You'll have to juggle the pattern and
hold spaces if you want just part of a line uppercased.

Or get Perl. :-)
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

tchrist@convex.COM (Tom Christiansen) (08/17/90)

In article <1990Aug16.232151.23436@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes:
>In article <3766@umbc3.UMBC.EDU>, rostamia@umbc5 writes:
>| Is there a way to convert characters to uppercase or to lowercase in sed?
>	y/a-z/A-Z/
>uppercases the pattern space.  You'll have to juggle the pattern and
>hold spaces if you want just part of a line uppercased.
>
>Or get Perl. :-)

Yes, the y command is a pain because of not being able to act
on just part of a line.

But, um, Randal has (understandably :-) been doing so much perl
he's attributed perl intelligence to sed, which just isn't so.

In sed you really have to do this:

    y/abcdefghijklmnopqrstuvxyz/ABCDEFGHIJKLMNOPQRSTUVXYZ/

And make sure they match up exactly.

--tom
--
  "UNIX was never designed to keep people from doing stupid things, because 
   that policy would also keep them from doing clever things." [Doug Gwyn]

maart@cs.vu.nl (Maarten Litmaath) (08/17/90)

In article <1990Aug16.232151.23436@iwarp.intel.com>,
	merlyn@iwarp.intel.com (Randal Schwartz) writes:
)In article <3766@umbc3.UMBC.EDU>, rostamia@umbc5 writes:
)| Is there a way to convert characters to uppercase or to lowercase in sed?
)| In EX the command
)| s/asdf/\U&/
)| changes the string asdf to ASDF, but ed and sed do not seem to be as
)| sophisticated as ex :-(
)| 
)| Any ideas?
)
)yeah, the not very well documented "y" command.
)
)	y/a-z/A-Z/

Doesn't work on SunOS 4.0.3c and a whole lotta other UNIX versions.  :-(

	y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/

POSIX had better fix this...
--
   "UNIX was never designed to keep people from doing stupid things, because
    that policy would also keep them from doing clever things."  (Doug Gwyn)

merlyn@iwarp.intel.com (Randal Schwartz) (08/18/90)

In article <7331@star.cs.vu.nl>, maart@cs (Maarten Litmaath) writes:
| )yeah, the not very well documented "y" command.
| )
| )	y/a-z/A-Z/
| 
| Doesn't work on SunOS 4.0.3c and a whole lotta other UNIX versions.  :-(
| 
| 	y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
| 
| POSIX had better fix this...

Hmm, it would have worked *after* being fed through the sed-to-Perl
translator... :-)

Shows you how much *I've* used that in sed.

Just another (former) sed hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

Dan_Jacobson@ATT.COM (08/18/90)

merlyn@iwarp.intel.com (Randal Schwartz) writes:
>yeah, the not very well documented "y" command.
>	y/a-z/A-Z/

bzzzzt. Minus 10 points! got to say:
y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
-- 
Dan_Jacobson@ATT.COM +1-708-979-6364