Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to change all but first letters to small leters

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
what i need is to change:

QWERTYUIO
ASDFG
ZXCVBNM


with

Qwertyuio
Asdfg
Zxcvbnm
 
in Perl?

Code:
[b]#!/usr/bin/perl[/b]

while (<DATA>) {
  print ucfirst lc($_);
}

__DATA__
QWERTYUIO
ASDFG
ZXCVBNM


Kind Regards
Duncan
 
Presuming it's always going to be the first character on each line you want to convert to upper case, this should do it:

[tt]awk ' { print substr($0,1,1) tolower(substr($0,2)) } '[/tt]

Annihilannic.
 
Hi

Duncan, I see you still not use the [tt]perl[/tt]'s switches. I think they are pretty. A read, loop, maybe a print too, for free.

Code:
perl -ne 'print ucfirst lc' inputfile
[gray]# or[/gray]
perl -pe 's/(.)(.*)/uc($1).lc$2/e' inputfile

Feherke.
 
Nice one feherke! I'll have to do some reading... :)


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top