The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl - converting selected characters to upper/lower case doubleminus UNIX for Dummies Questions & Answers 2 05-19-2008 01:13 AM
Accepting Upper and Lower case lweegp Shell Programming and Scripting 8 12-08-2007 06:57 PM
UNIX command to reverese lower and upper case rfourn Shell Programming and Scripting 6 12-07-2007 10:33 PM
lower case to upper case string conversion in shell script dchalavadi UNIX for Dummies Questions & Answers 3 05-29-2002 12:07 AM
Upper And Lower Case pciatto Shell Programming and Scripting 1 04-29-2002 12:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-12-2008
rahulkav rahulkav is offline
Registered User
  
 

Join Date: Aug 2008
Location: Reading, UK
Posts: 11
Change Case UPPER-lower & lower - UPPER

Hi All,

I have a wrongly typed file i.e. Upper case letters are typed as lower and vice cerse i.e. "tHIS IS AN unix FORUM." I would like to do a conversion such that out out should be This is an UNIX forum' I would like to do in shell script . Any pointers? I know that we can use tr -s or typeset but using those I am able to convert either in either all lower or all upper.


Can we do this using awk by taking each character in a array and converting.

Any help will be hightly appreciated.

cheers,
  #2 (permalink)  
Old 09-12-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Not pretty but works:
Code:
sed 'y/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/'
A shorter/more elegant version would be interessting.
  #3 (permalink)  
Old 09-12-2008
unknown123 unknown123 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 19
try below code:

tr -s '[a-z][A-Z]' '[A-Z][a-z]' <input_file >output_file

it works fine for me...

let me know if you still face any issues.

enjy................
  #4 (permalink)  
Old 09-12-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 560
Quote:
Originally Posted by unknown123 View Post
try below code:

tr -s '[a-z][A-Z]' '[A-Z][a-z]' <input_file >output_file

it works fine for me...

let me know if you still face any issues.

enjy................

It will work even without -s
  #5 (permalink)  
Old 09-12-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
While this will work perfectly on most systems, it is not portable to all systems.

Code:
/home/franklin >uname -a
HP-UX csu02 B.11.00 A 9000/800 126484691 two-user license

/home/franklin >tr -s '[a-z][A-Z]' '[A-Z][a-z]' etik                         
tr: The combination of options and String parameters is not legal.
Usage: tr [ -c | -cds | -cs | -ds | -s ] [-A] String1 String2
       tr [ -cd | -cs | -d | -s ] [-A] String1
Code:
/home/franklin >tr '[a-z][A-Z]' '[A-Z][a-z]' etik                         
tr: The combination of options and String parameters is not legal.
Usage: tr [ -c | -cds | -cs | -ds | -s ] [-A] String1 String2
       tr [ -cd | -cs | -d | -s ] [-A] String1
Regards
  #6 (permalink)  
Old 09-12-2008
mahendrt mahendrt is offline
Registered User
  
 

Join Date: Aug 2008
Location: Pune,India
Posts: 10
Quote:
Originally Posted by unknown123 View Post
try below code:

tr -s '[a-z][A-Z]' '[A-Z][a-z]' <input_file >output_file

it works fine for me...

let me know if you still face any issues.

enjy................
This works fine for me, mine is AIX
  #7 (permalink)  
Old 09-14-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
Code:
cat filename | tr "[:upper:][:lower:]" "[:lower:][:upper:]"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0