Sed - Lower case single characters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sed - Lower case single characters
# 1  
Old 04-28-2005
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  
Old 04-28-2005
Code:
$ cat file1
i am unix guy
$ sed 's/i /I/g' file1
Iam unix guy
$

# 3  
Old 12-07-2007
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  
Old 12-08-2007
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.
# 5  
Old 12-08-2007
Quote:
Originally Posted by ramkrix
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
# 6  
Old 12-08-2007
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
# 7  
Old 12-09-2007
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.

Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert text to lower case except the strings within single quotes

Shell : bash that comes with RHEL 6.7 I have SQL scripts like below. I want to convert all the text in these files to lower case except the strings enclosed within single quotes . Any idea how I can achieve this ? Sample text: $ cat sample.txt SELECT ... (6 Replies)
Discussion started by: John K
6 Replies

2. Shell Programming and Scripting

Change first letter of a word from lower case to upper case

Hi all, I am trying to find a way to change first letter in a word from lower case to upper case. It should be done for each first word in text or in paragraph, and also for each word after punctuation like . ; : ! ?I found the following command sed -i 's/\s*./\U&\E/g' $@ filenamebut... (7 Replies)
Discussion started by: georgi58
7 Replies

3. Shell Programming and Scripting

Conversion from Upper Case to Lower Case Condition based

Hello Unix Gurus : It would be really appreciative if can find a solution for this . I have records in a file . I need to Capitalize the records based on condition . For Example i tried the following Command COMMAND --> fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
Discussion started by: tsbiju
12 Replies

4. Shell Programming and Scripting

[Solved] Change Upper case to Lower case in C shell

Is there a command that can switch a character variable from UPPER case to lower case? like foreach AC ( ABC BCD PLL QIO) set ac `COMMAND($AC)` ... end Thanks a lot! (3 Replies)
Discussion started by: rockytodd
3 Replies

5. Shell Programming and Scripting

data array needs to change upper case to lower case

Hi all, i have a data array as followes. ARRAY=DFSG345GGG ARRAY=234FDFG090 ARRAY=VDFVGBGHH so on.......... i need all english letters to be change to lower case. So i am expecting to see ARRAY=dfsg345ggg ARRAY=234fdfg090 ARRAY=vdfvgbghh so on........ If i have to copy this data in... (8 Replies)
Discussion started by: usustarr
8 Replies

6. Shell Programming and Scripting

Convert contents of file to lower case with SED

Hi I what to add option to existing sed code to convert target file to lower case #!/bin/ksh SOURCE_DATA_DEST=/ora TARGET_DATA_DEST=/home/oracle/alexz TARGET_DB_SID=T102_test sed -e "s/REUSE/SET/g" \ -e "s/NORESETLOGS/RESETLOGS/g" \ T102_ccf.sql > target.sql Thanks (2 Replies)
Discussion started by: zam
2 Replies

7. Shell Programming and Scripting

how to convert value in a variable from upper case to lower case

Hi, I have a variable $Ctrcd which contains country names in upper case and i want to convert them into lower case. I have tried so many solutions from already existing threads but couldn't get the correct one. Can anybody help me with this..... Thanks a lot.. (2 Replies)
Discussion started by: manmeet
2 Replies

8. UNIX for Dummies Questions & Answers

Perl - converting selected characters to upper/lower case

Using STDIN, how can I use perl to take an input string, with all lower case letters in the first five characters, and convert them to uppercase... then take all uppercase letters in the second five characters and convert them to lowercase. Example: MichaelSmith to michaELSMIth Thank you! (2 Replies)
Discussion started by: doubleminus
2 Replies

9. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

10. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question