UNIX command to reverese lower and upper case | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

UNIX command to reverese lower and upper case

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-09-2007
rfourn rfourn is offline
Registered User
 
Join Date: Jun 2007
Last Activity: 18 July 2007, 5:38 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
UNIX command to reverese lower and upper case

im trying to find a command to
change all upper case to lower case and
all lower case to upper case.
for example:
file is 'RED sox'
need it changed to 'red SOX'

tried tr 'a-zA-Z' 'A-Za-z' didn't work

what an i missing??

thanx for the help
Sponsored Links
    #2  
Old 06-09-2007
porter porter is offline Forum Advisor  
Registered User
 
Join Date: Jan 2007
Last Activity: 8 January 2008, 6:50 PM EST
Posts: 2,965
Thanks: 0
Thanked 5 Times in 5 Posts
I tried


Code:
tr "a-zA-Z" "A-Za-z"

and that worked on Etch.
Sponsored Links
    #3  
Old 06-09-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 24 October 2014, 11:45 AM EDT
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 437 Times in 261 Posts
I would expect it to work with single quotes as well:
Code:
$ echo RED sox | tr 'a-zA-Z' 'A-Za-z'
red SOX
$

rfourn, what version of Unix are you using? And what shell?

The pre-posix USG based version of tr used to require brackets around a range. On such a version,
tr '[a-z]' '[A-Z]'
would work for sure. I don't remember for sure if multiple ranges would work, but I think they did. If so,
tr '[a-z][A-Z]' '[A-Z][a-z]'
would work. BSD never required the brackets and Posix adopted the BSD style for ranges. Legacy USG scripts will tend to work with a Posix version of tr because with
tr '[a-z]' '[A-Z]'
brackets are being replaced by themselves. A legacy USG scrip with code like:
tr 'a-z'
where the 'a-z' is supposed to be exactly 3 characters will fail though.

I hope you aren't using a very old version of Unix with behavior like this. But if you are, it is especially crucial that you mention your Unix version with every question.
    #4  
Old 12-07-2007
ramkrix ramkrix is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 2 August 2011, 12:13 PM EDT
Location: TamilNadu,INDIA
Posts: 77
Thanks: 0
Thanked 1 Time in 1 Post
Error

Hi version of UNIX is SOLARIS 9

but neither of the aforesaid commands is working..

Will you suggest how to execute the same in SOLARIS9?
Sponsored Links
    #5  
Old 12-07-2007
V3l0 V3l0 is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 10 April 2008, 10:18 AM EDT
Location: Belgium & France
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
echo RED sox | tr '[:upper:][:lower:]' '[:lower:][:upper:]'
red SOX
Sponsored Links
    #6  
Old 12-07-2007
prowla prowla is offline
Read Only
 
Join Date: Nov 2007
Last Activity: 16 July 2012, 4:02 PM EDT
Posts: 165
Thanks: 0
Thanked 2 Times in 2 Posts
Works for me on HP-UX, Solaris, and Cygwin on Windoze.

# uname -a
SunOS mysun 5.10 Generic_118833-17 sun4v sparc SUNW,Sun-Fire-T200# echo RED sox | tr 'a-zA-Z' 'A-Za-z'
RED sox

# uname -a
HP-UX myhp B.11.11 U 9000/800 158454601 unlimited-user license
# echo RED sox | tr 'a-zA-Z' 'A-Za-z'
red SOX

$ uname -a
CYGWIN_NT-5.0 mypc 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin
$ echo RED sox | tr 'a-zA-Z' 'A-Za-z'
red SOX
Sponsored Links
    #7  
Old 12-07-2007
ramkrix ramkrix is offline
Registered User
 
Join Date: Dec 2007
Last Activity: 2 August 2011, 12:13 PM EDT
Location: TamilNadu,INDIA
Posts: 77
Thanks: 0
Thanked 1 Time in 1 Post
Bug Thanks V310

echo RED sox | tr '[:upper:][:lower:]' '[:lower:][:upper:]'
red SOX

This is perfectly working in my Solaris OS

SunOS XXXXXXX 5.10 Generic_118833-24 sun4u sparc SUNW,Netra-T12
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Conversion from Upper Case to Lower Case Condition based tsbiju Shell Programming and Scripting 12 07-08-2011 02:53 PM
[Solved] Change Upper case to Lower case in C shell rockytodd Shell Programming and Scripting 3 11-04-2010 12:57 PM
data array needs to change upper case to lower case usustarr Shell Programming and Scripting 8 04-16-2010 05:33 PM
Change Case UPPER-lower & lower - UPPER rahulkav Shell Programming and Scripting 7 09-14-2008 02:50 AM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-29-2002 12:07 AM



All times are GMT -4. The time now is 02:08 PM.