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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

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
Script needed to select and delete lower case and mixed case records abhilash mn Shell Programming and Scripting 1 03-17-2008 08:00 AM
Accepting Upper and Lower case lweegp Shell Programming and Scripting 8 12-08-2007 06:57 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 Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-28-2005
zlindner zlindner is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 1
Sed - Lower case single characters

Hello,

I have a file where I am supposed to convert all the single i characters to uppercase, but when I try, it converts all the i's inside of words to uppercase as well.

I tried doing:

cat filename | sed 's/i/I/g'

but that obviously does not work.

Any help would be greatly appreciated.

Thanks.
  #2 (permalink)  
Old 04-28-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Code:

$ cat file1
i am unix guy
$ sed 's/i /I/g' file1
Iam unix guy
$
  #3 (permalink)  
Old 12-07-2007
ramkrix ramkrix is offline
Registered User
  
 

Join Date: Dec 2007
Location: TamilNadu,INDIA
Posts: 52
sed 's/ i / I /g'

Single space prefixed and suffixex with both upper and lower case I

Please reply back whether it works or not
  #4 (permalink)  
Old 12-08-2007
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,302
Quote:
Originally Posted by ramkrix View Post
sed 's/ i / I /g'

Single space prefixed and suffixex with both upper and lower case I

Please reply back whether it works or not
It's not as easy as it seems, what if you have a file like this?

i'm the big brother.
i never drink water, i
only drink beer.
i've got to do this job.
Yes, i can do it.


There should be more possibilities but try this one:

Code:
sed -e 's/i/I/g' -e 's/\([a-zA-Z].*\)I\([a-zA-Z].*\)/\1i\2/g' file
Regards
  #5 (permalink)  
Old 12-08-2007
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 707
Hi.

Using the boundary assertions of regular expressions as gus2000 mentioned:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate changing case considering "word" boundaries.

set -o nounset
echo

debug=":"
debug="echo"

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash sed

echo

FILE=${1-data1}
echo " Input file:"
cat $FILE

echo
echo " Results from sed:"
sed 's_\<i\>_I_g' $FILE

exit 0
Producing:
Code:
% ./s1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
GNU sed version 4.1.2

 Input file:
i'm the big brother.
i never drink water, i
only drink beer.
i've got to do this job.
Yes, i can do it.

 Results from sed:
I'm the big brother.
I never drink water, I
only drink beer.
I've got to do this job.
Yes, I can do it.
This might vary with your version of sed, but I think it's fairly standard ... cheers, drl
  #6 (permalink)  
Old 12-09-2007
ramkrix ramkrix is offline
Registered User
  
 

Join Date: Dec 2007
Location: TamilNadu,INDIA
Posts: 52
Thanks Franklin for pointing out what I missed. But let me check the command with my solaris m/c. As its my week end here I cant access my m/c which is my office.

  #7 (permalink)  
Old 12-08-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
Well you can specify regex "word delimiters":

Code:
/\bWORD\b/                          # word is framed by blanks
/\<WORD\>/                          # match whole word inside < >
/[[:blank:]]WORD[[:blank:]]/        # word is framed by blanks (alternate)
Your choices will vary with your Unix distro and sed version.
Closed Thread

Bookmarks

Tags
regex, regular expressions

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 01:13 AM.


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