Replace a string in quote to uppercase


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace a string in quote to uppercase
# 1  
Old 02-03-2010
Replace a string in quote to uppercase

Hi,
I need to find all strings in single quote and change the case of the string to UPPER.

Example:

Input:
xyz abc ccc 'zxxx7U'
dfsdf sdfdd aaa 'oR77' and 'or88'

Output:
xyz abc ccc 'ZXXX7U'
dfsdf sdfdd aaa 'OR77' and 'OR88'

Appreciate your help!!

Thanks
Selva
# 2  
Old 02-03-2010
Code:
sed "s/'\(.*\)'/'\U\1'/" file_name


HTH,
PL
# 3  
Old 02-03-2010
I think a lazy match should be used (this works in GNU sed on matches on the same line)
Code:
sed "s/'\([^']*\)'/'\U\1'/g"

# 4  
Old 02-03-2010
Code:
awk '{for (i=1;i<=NF;i++) {if ($i~/^'\''.*'\''$/) $i=toupper($i)}}1' urfile

interesting, one single quota need be used as '\'' in awk (three single quotas)
# 5  
Old 02-04-2010
The \U does not work, other parts work.

\U works only in VI editor, but not while part of a script.

Last edited by selkum; 02-04-2010 at 03:34 PM..
# 6  
Old 02-04-2010
The solution of rdcwayx should work.

Another one:
Code:
awk -F"'" '{for(i=2;i<NF;i+=2){$i=toupper($i)}}1' OFS="'" file

# 7  
Old 02-05-2010
It works now. thanks a lot.....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Enclose String in single quote

I have a comma separated file which contains data like; File header: ID_WVR,SAK_WVR_SVC,DSC_WVR_WVC,SAK_PROCEDURE,CODES,CDE_PROC_MOD ,CDE_PROC_MOD_2 ,CDE_PROC_MOD_3 File Detail: AMR,5100,Total Services,305,D0120,,, AMR,5101,Periodic Services,40702,H2011,U1,, AMR,5112,Day... (4 Replies)
Discussion started by: jnrohit2k
4 Replies

2. Shell Programming and Scripting

How to uppercase matching line when string found?

Hello, Could you please help me how to search the string in a file, and when found; change the existing line to uppercase in command line? I tried: ?whichcommand? -A "EXT" fileA | awk '{print tolower($0)}' | tee fileB tr command simply converts entire file to uppercase but this is not what... (4 Replies)
Discussion started by: baris35
4 Replies

3. Shell Programming and Scripting

Replace double quotes with a single quote within a double quoted string

Hi Froum. I have tried in vain to find a solution for this problem - I'm trying to replace any double quotes within a quoted string with a single quote, leaving everything else as is. I have the following data: Before: ... (32 Replies)
Discussion started by: pchang
32 Replies

4. Shell Programming and Scripting

How to replace quote symbol(") and dot(.) with some other values!!

Hi , I have below input file 1.order number is useful. 2.vendor_id is produced. 3.the vandor name is "malawar". I want output file like 1. order number is useful. 2. vendor_id is produced. 3. the vandor name is VmalawarV. in input file line number 1.order number there is no... (4 Replies)
Discussion started by: vinothsekark
4 Replies

5. Shell Programming and Scripting

Check whether a string begin with uppercase, lowercase or digit!

Hi every body! I wrote script on Fedora (bash shell) to check whether a tring enter from user console is start with a uppercase/lowercase letter or a digit. But with this script i have some problem when I enter from character from 'b' to 'z' --> result is uppercase. This code look like ok but i... (9 Replies)
Discussion started by: nguyendu0102
9 Replies

6. UNIX for Dummies Questions & Answers

find single quote in a string and replace it

Hi, I have variable inside shell script - from_item. from_item = 40.1'1/16 i have to first find out whether FROM_ITEM contains single quote('). If yes, then that need to be replace with two quotes (''). How to do it inside shell script? Please note that inside shell script........ (4 Replies)
Discussion started by: yogichavan
4 Replies

7. Shell Programming and Scripting

replace a single quote using sed command.

Hi, How do I replace the charachters = '*' to = '^' using Sed commands. As I have several * in the script, thus I have to replace the single quotes too. Please let me know any solution. I have tried the escape character backslash '\' but it doesnt help. sed "s/= \'*\'/=... (2 Replies)
Discussion started by: prachifun
2 Replies

8. Shell Programming and Scripting

Replacing the string after certain # of double quote

Could you please help in unix scripting for below scenario... In my input file, there might be a chance of having a string ( Ex:"99999") after 5th double quote for each record. I need to replace it with a space. Ex : Input : "abcdef","12345","99999","0986"... (3 Replies)
Discussion started by: vsairam
3 Replies

9. UNIX for Dummies Questions & Answers

Convert string to uppercase

i have this piece of small code that checks for *.CSV files. NUMFILES=`ls -1 *.CSV | wc -l` for filename in $(ls -1 *.CSV) do ... done it works only if the files has an uppercase of *.CSV extension. however, when there is a file of the same type but has lowercase *.csv... (1 Reply)
Discussion started by: wtolentino
1 Replies

10. Shell Programming and Scripting

sed: how to replace regex with a ' (quote) mark

I've got a text file which has " marks where it there should be ' marks. I tried to do it with sed, but it won't allow me to escape the ' mark. Here's what I tried to do: sed 's/"/\\'/g' file.txt How can this be done? Thanks (3 Replies)
Discussion started by: CraigMoore
3 Replies
Login or Register to Ask a Question