Need help to change tokenized string case


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to change tokenized string case
# 1  
Old 09-30-2012
Need help to change tokenized string case

I'm trying to change the string cases for a particular column, but can't figure how do to it with sed. Example:

Strings (space as delimiter):
write group MYGROUP MySpecialGroup /local/users/mygroup
write group HISGROUP HisSpecialGroup /local/users/hisgroup
write group HerGroup HerSpecialGroup /local/users/hergroup

Desire output:
write group mygroup MySpecialGroup /local/users/mygroup
write group hisgroup HisSpecialGroup /local/users/hisgroup
write group hergroup HerSpecialGroup /local/users/hergroup

I just want to change the string to lower case for 3rd column and rest should be untouch...

Please advise.
Thanks.
# 2  
Old 09-30-2012
try this..

Code:
awk '{ $3=tolower($3)}1' file

# 3  
Old 09-30-2012
Awesome pamu, this is exactly what I'm looking for. Thanks! Smilie

I have another question about running this selectively on these lines. Supposed I just want to convert the lower case if the line starts with "write..." but not others. How can I do this in awk? I tried grep, but it will not print those that are not "write...". And I want to print all these lines...

Thanks. Smilie
# 4  
Old 09-30-2012
Quote:
Originally Posted by fluffy_ko
Supposed I just want to convert the lower case if the line starts with "write..."
try this....

Code:
awk '/^write/{ $3=tolower($3)}1' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Change lowercase to upper case

dear all, i have file input ABCDE_Asta_Key_Park,COJ050,10.142.3.150 C_BDEFG_City_Lake,C_BIR0,10.135.3.6 C_FDGEBIR_Axaudia,C_ABIR1,10.135.3.34 I want to change lowercase in to uppercase for all strings output ABCDE_ASTA_KEY_PARK,COJ050,10.142.3.150 C_BDEFG_CITY_LAKE,C_BIR0,10.135.3.6... (5 Replies)
Discussion started by: radius
5 Replies

3. Shell Programming and Scripting

Change case preserving the same case

how can i do a case insensitive search/replace but keep the same case? e.g., i want to change a word like apple-pie to orange-cake but for the first word if the first letter of the keyword or the letter after the - is capitalised i want to preserve that e.g., if the before is: ... (5 Replies)
Discussion started by: vanessafan99
5 Replies

4. UNIX for Dummies Questions & Answers

How to change the second to nth string in lower case

I have a file which contains something like this REIGN ANGEL i want to change REIGN to Reign and ANGEL to Angel. (6 Replies)
Discussion started by: reignangel2003
6 Replies

5. 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

6. UNIX for Dummies Questions & Answers

How to change Case of a string(BASH Scripting)?

Is there any inbuilt functionality in Unix shell script so that i can able to convert lower case string input to an upper case? I dont want to use high level languages like java,python or perl for doing the job. (2 Replies)
Discussion started by: pinga123
2 Replies

7. 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

8. Shell Programming and Scripting

change filenames to Proper case

Hi, I have files with all its characters in lower cases. I need to change them to "proper case" (starting char to be come Upper case). How can I? Pls suggest. for e.g. xyz.txt should become Xyz.txt TIA Prvn (7 Replies)
Discussion started by: prvnrk
7 Replies

9. UNIX for Dummies Questions & Answers

change character case

i need to change character case inside a script file. How i can do that? any fucntion? thanks (3 Replies)
Discussion started by: ajaya
3 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