Computing.Net > Forums > Unix > command for changing upper and lowe

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

command for changing upper and lowe

Reply to Message Icon

Original Message
Name: htnkd
Date: September 16, 2004 at 06:46:32 Pacific
Subject: command for changing upper and lowe
OS: linux
CPU/Ram: 500
Comment:

Need help with a command for changing the following

KREMS|XXXX YYYY|HHHH|
YYYY UUUUU |YYYYYYYYY|IIIIII


need to change it to:
Krems|Xxxxx Yxxx|Hhhh|
Yyyy Uuuuu |Yyyyyyyyy|Iiiiii

I have a large file with proper names that need to be converted to upper and lower case

thanks


Report Offensive Message For Removal


Response Number 1
Name: Jim Boothe
Date: September 16, 2004 at 08:22:52 Pacific
Reply: (edit)

The following solution leaves each character as is that follows either start of line or space or bar character, and downshifts all the rest.

I leave the first character as is (rather than upshift) because you may want something like John deHavilland.  But if you do want to upshift all first characters, then remove the #.

awk '{\
newline=""
cap=1
for (i=1;i<=length;i++)
   {x=substr($0,i,1)
    if (x=="|" || x==" ")
       cap=1
    else
       if (cap==1)
          {#x=toupper(x)
           cap=0}
       else
          x=tolower(x)
    newline=newline x}
print newline
}' largefile


Report Offensive Follow Up For Removal

Response Number 2
Name: htnkd
Date: September 16, 2004 at 11:23:25 Pacific
Reply: (edit)

works fine except for if I have the following

18.yyyyyy-kkkkkk|

need it to be
18.Yyyyyy-Kkkkkk|

any ideas on how to include these as well


thanks


Report Offensive Follow Up For Removal

Response Number 3
Name: Jim Boothe
Date: September 16, 2004 at 12:06:18 Pacific
Reply: (edit)

Change the if-statement to:

if (x=="|" || x==" " || x=="." || x=="-")

and since you want to upshift (not just downshift), then take out the #.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software