changing_case_of_strings

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Subject: Re: Converting Case Lettering
From: Ken Irving <jkirving@mosquitonet.com>
Date: Mon, 12 Jun 2000 15:31:13 -0800


On Mon, Jun 12, 2000 at 03:57:12PM -0500, Bret Hughes wrote:
> SoloCDM wrote:
> 
> > What commands convert casing to upper, lower, and proper (proper: as
> > in Virginia)?
> >
> 
> tr will translate from on to the other.  take a look at man tr.  Also a
> thread awhile back that mentioned this.  some thing like cat file |tr
> [a-z] [A-Z]>newfile will probably come close but this is a guess.
> 
> For the Title Case Situation you will probably have to get tricky.
> 

Perl's ucfirst() function can do this, e.g.,

    $ echo virginia | perl -ne 'print $_, ucfirst';
    virginia
    Virginia
    $ 
    $ perldoc -f ucfirst
    =item ucfirst EXPR
    
    =item ucfirst
    
    Returns the value of EXPR with the first character uppercased.  This is
    the internal function implementing the C<\u> escape in double-quoted strings.
    Respects current LC_CTYPE locale if C<use locale> in force.  See L<perllocale>.
    
    If EXPR is omitted, uses C<$_>.

===

Subject: Re: Converting Case Lettering
From: Enrico Payne <enricop@pharma.co.za>
Date: Tue, 13 Jun 2000 07:53:49 +0200 (SAST)

On Mon, 12 Jun 2000, Bret Hughes wrote:

> SoloCDM wrote:
> 
> > What commands convert casing to upper, lower, and proper (proper: as
> > in Virginia)?
> >
> > Note: Detailed Document(s) and Sample(s) are more than welcome.
> >       When you reply to this message, please include
> >       the mailing list and my address.

> tr will translate from on to the other.  take a look at man tr.  Also a
> thread awhile back that mentioned this.  some thing like cat file |tr
> [a-z] [A-Z]>newfile will probably come close but this is a guess.
> 
> For the Title Case Situation you will probably have to get tricky.


The best way that I have found is to use the following

VARIABLE=`echo $VARIABLE|dd conv=lcase 2>/dev/null`

Do a man on dd to see the other useful goodies.

The 2>/dev/null is optional, but does gives a cleaner output.

===


the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu