Sed: tolower()

Sed: tolower()

Post by TeamTerradact » Thu, 09 Jan 2003 18:39:21



I don't know if I should be using awk, sed, or another, but my basic
question is the changing of case in a file:

--text1.txt--

some_dir=C:\\PROGRA~1\\GNU\\CVS
dir_help=E:\\DJGPP\\MAN\\MAN1
whose_idea=D:\\MY DOCUMENTS\\TURNIP GREENS\\PLASTIC

--text1.txt--

I assume that I need sed, because it has \1 \2... operators.  I want
to change case of anything after double backslashes from uppercase to
Mixed Case (yea, I know -- bad practice.  But c'mon... this is Win9x
here).

How would I set this up to use a tolower() command?

For the first part, I'm guessing that I need the following to search
for the 1st character in uppercase, then search for 0-or-more
uppercase letters (using \( and \) for later retrieval):

/[A-Z]\([A-Z]*\)/

From this point, I don't know how to break off (pipe?) and change all
the uppercase letters (between \( and \) ) to lowercase.  I'm trying
to find a FAQ or something else that explains this (if anyone knows of
one).  If a FAQ doesn't exist that explains this, does anyone know how
to do it?

-TeamTerradactyl
 teamterradactyl at users dot sourceforge dot net

 
 
 

Sed: tolower()

Post by Stephane Chazela » Thu, 09 Jan 2003 18:52:37


[...]
Quote:> /[A-Z]\([A-Z]*\)/

> From this point, I don't know how to break off (pipe?) and change all
> the uppercase letters (between \( and \) ) to lowercase.  I'm trying
> to find a FAQ or something else that explains this (if anyone knows of
> one).  If a FAQ doesn't exist that explains this, does anyone know how
> to do it?

[...]

Use perl:

$ echo QWE-QWE | perl -pe 's/([A-Z])([A-Z]*)/$1\L$2/g'
Qwe-Qwe

It's possible with sed but would be much complicated.

--
Stphane

 
 
 

Sed: tolower()

Post by John » Thu, 09 Jan 2003 18:56:23



> I don't know if I should be using awk, sed, or another, but my basic
> question is the changing of case in a file:

> --text1.txt--

> some_dir=C:\\PROGRA~1\\GNU\\CVS
> dir_help=E:\\DJGPP\\MAN\\MAN1
> whose_idea=D:\\MY DOCUMENTS\\TURNIP GREENS\\PLASTIC

> --text1.txt--

> I assume that I need sed, because it has \1 \2... operators.  I want
> to change case of anything after double backslashes from uppercase to
> Mixed Case (yea, I know -- bad practice.  But c'mon... this is Win9x
> here).

> How would I set this up to use a tolower() command?

> For the first part, I'm guessing that I need the following to search
> for the 1st character in uppercase, then search for 0-or-more
> uppercase letters (using \( and \) for later retrieval):

> /[A-Z]\([A-Z]*\)/

> From this point, I don't know how to break off (pipe?) and change all
> the uppercase letters (between \( and \) ) to lowercase.  I'm trying

There *might* be an easier way.

But first to answer your question. The way to do tolower in sed is
with y -- y/ABC...XYZ/abc...xyz/ but because you want to do it
to only part of the line, you will need what can for the uninitiated
seem fairly daunting transfers between the hold and pattern spaces.

So, can you cheat?
Well you can, if the problem can be recast as:
    1) change *everything* to lower case, then
    2) change the single letter between the equals sign and the colon to upper case

You could use sed for both parts, but it would seem more natural to use
tr for step 1, and pipe into sed for step 2.

John.

 
 
 

Sed: tolower()

Post by Peter S Tillie » Thu, 09 Jan 2003 20:37:30





> [...]
> > /[A-Z]\([A-Z]*\)/

> > From this point, I don't know how to break off (pipe?) and change
all
> > the uppercase letters (between \( and \) ) to lowercase.  I'm trying
> > to find a FAQ or something else that explains this (if anyone knows
of
> > one).  If a FAQ doesn't exist that explains this, does anyone know
how
> > to do it?
> [...]

> Use perl:

> $ echo QWE-QWE | perl -pe 's/([A-Z])([A-Z]*)/$1\L$2/g'
> Qwe-Qwe

> It's possible with sed but would be much complicated.

Of course with GNU sed 4.0 you can do:

$ echo QWE-QWE | sed 's/\([A-Z]\)\([A-Z]*\)/\1\L\2/g'
Qwe-Qwe

which isn't all that complicated ;-)

HTH
--
Peter S Tillier
This post represents the views of the author and does not
necessarily accurately represent the views of BT.

 
 
 

Sed: tolower()

Post by John W. Krah » Thu, 09 Jan 2003 23:05:35




> [...]
> > /[A-Z]\([A-Z]*\)/

> > From this point, I don't know how to break off (pipe?) and change all
> > the uppercase letters (between \( and \) ) to lowercase.  I'm trying
> > to find a FAQ or something else that explains this (if anyone knows of
> > one).  If a FAQ doesn't exist that explains this, does anyone know how
> > to do it?
> [...]

> Use perl:

> $ echo QWE-QWE | perl -pe 's/([A-Z])([A-Z]*)/$1\L$2/g'
> Qwe-Qwe

> It's possible with sed but would be much complicated.

$ echo QWE-Q?-q? | perl -Mlocale -pe 's/(\w+)/\u\L$1/g'
Qwe-Q?-Q?

John
--
use Perl;
program
fulfillment

 
 
 

Sed: tolower()

Post by Rikard Bosnjakovi » Sun, 12 Jan 2003 08:45:00


Quote:> But first to answer your question. The way to do tolower in sed is
> with y -- y/ABC...XYZ/abc...xyz/ but because you want to do it

A more readable version is 'y/[A-Z]/[a-z]/'.

--
Friendly,

Rikard

 
 
 

Sed: tolower()

Post by dmer.. » Tue, 14 Jan 2003 02:33:57




Quote:>> But first to answer your question. The way to do tolower in sed is
>> with y -- y/ABC...XYZ/abc...xyz/ but because you want to do it

> A more readable version is 'y/[A-Z]/[a-z]/'.

That won't do what you think it does:

   $ echo ABCDEFGHIJKLMNOPQRSTUVWXYZ | sed 'y/[A-Z]/[a-z]/'
   aBCDEFGHIJKLMNOPQRSTUVWXYz

--
Dan Mercer

 
 
 

Sed: tolower()

Post by Bobby Higgin » Sat, 25 Jan 2003 11:22:33


try using
echo "ABCDEFGHIJKLMNOPQRSTUVWXYZ"  |    tr [A-Z]  [a-z]



> >> But first to answer your question. The way to do tolower in sed is
> >> with y -- y/ABC...XYZ/abc...xyz/ but because you want to do it

> > A more readable version is 'y/[A-Z]/[a-z]/'.

> That won't do what you think it does:

>    $ echo ABCDEFGHIJKLMNOPQRSTUVWXYZ | sed 'y/[A-Z]/[a-z]/'
>    aBCDEFGHIJKLMNOPQRSTUVWXYz

> --
> Dan Mercer


 
 
 

1. sed sed sed

On solaris 9 - why are there multiple copies of sed installed.  One in /usr/ucb
owned by the SUNWscpu third party package, /usr/xpg4/bin/sed by SUNWxcu4, and
one in /usr/bin owned by SUNWcsu.  I've looked on other Sun machines not
maintained by me and the same versions of sed are in the same place owned by the
same packages.

Why the multiple copies?

2. Help! problem with static build

3. . 2 sed FAQs, sed exes, sed cetras; URLs

4. Help! NOTICE: alloc: /: file system full

5. SED SED SED...

6. Real Time replication for linux

7. (sed 1q ; sed 2q) : no output from 2nd 'sed'

8. Keyboard acting up in X

9. Ksh Question - tolower() ?

10. SUNOS NAWK - TOLOWER - In a print statement convert string to lower case

11. tolower with tr command question

12. (patch for Bash) toupper/tolower, isupper/islower, etc...

13. ToUpper() and ToLower() functions for AWK