sed help - convert a string of form ABC_DEF_GHI to AbcDefGhi


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed help - convert a string of form ABC_DEF_GHI to AbcDefGhi
# 1  
Old 12-27-2010
sed help - convert a string of form ABC_DEF_GHI to AbcDefGhi

How can covert a string of form ABC_DEF_GHI to AbcDefGhi using any online command such as sed etc. ?

Thanks.
# 2  
Old 12-27-2010
Hi,

Using 'perl':
Code:
$ cat infile
ABC_DEF_GHI
$ perl -pe '$_=lc($_); s/^(.)/uc($1)/e; s/_(.)/uc($1)/eg;' infile
AbcDefGhi

Regards,
Birei
# 3  
Old 12-27-2010
HI Frozen,
is the length of each string is same ,i mean 3chars_3chars_3chars or it does varry.
regards,
sanjay
# 4  
Old 12-27-2010
Code:
echo "ABC_DEF_GHI" | awk -F_ '{for(i=1;i<=NF;i++) $i=substr($i,1,1) tolower(substr($i,2)); print}' OFS=

output:
Code:
AbcDefGhi

for
Code:
echo "ABC_DEF_asYTYHGG_DSDSDSDSD_dfdjfhdjfh_232323" | awk -F_ '{for(i=1;i<=NF;i++) $i=substr($i,1,1) tolower(substr($i,2)); print}' OFS=

output:
Code:
AbcDefasytyhggDsdsdsdsddfdjfhdjfh232323


Last edited by anurag.singh; 12-27-2010 at 10:31 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: Storing string in array(triangular form)

I have a string like below. Now i want to split this string like below and put the value in the array using awk. I am able to do it using bash but getting no clue for doing it in awk O/P A=0 A=01 A=014 A=0143 A=01438 A=014387 A=0143876 A=01438765 A=014387650 ... (7 Replies)
Discussion started by: siramitsharma
7 Replies

2. Shell Programming and Scripting

Decimal conversion number of the form x.xx to 0x.xx, sed?

Hello I have a file of the form ... num 0.12 num num num 25.53 num num num 7.82 num num ...... and I want to convert the 2nd field of each line adding a "0" at the numbers >= 0 and < 10 so the output will have the form: ... num 00.12 num num num 25.53 num num num 07.82 num... (10 Replies)
Discussion started by: phaethon
10 Replies

3. Shell Programming and Scripting

Copy last third char form string

HI Input A.txt ABC907 ABC907_1B_9 ABC985 ABC985_1A_9 ABC985 ABC985_1B_9 ABC985 ABC985_1C_9 ABC05037 ABC05037_1A_9 ABC05037 ABC05037_1B_9 Base of column 2 last third char. If It is A the 1,if B then 2 If C then 3 File B.txt ABC907 ABC907_1B_9 2 ABC985 ABC985_1A_9 1 ABC985... (8 Replies)
Discussion started by: asavaliya
8 Replies

4. Shell Programming and Scripting

Convert string using sed

I have a couple structure definitions in my input code. For example: struct node { int val; struct node *next; }; or typedef struct { int numer; int denom; } Rational; I used the following line to convert them into one line and copy it twice. sed '/struct*{/{:l... (3 Replies)
Discussion started by: James Denton
3 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

Filter date and time form a file using sed command

I want to filter out the date and time from this line in a file. How to do this using sed command. on Tue Apr 19 00:48:29 2011 (12 Replies)
Discussion started by: vineet.dhingra
12 Replies

7. Shell Programming and Scripting

help - sed - insert space between string of form XxxAxxBcx, without replacing the pattern

If the string is of the pattern XxxXyzAbc... The expected out put from sed has to be Xxx Xyz Abc ... eg: if the string is QcfEfQfs, then the expected output is Qcf Ef Efs. If i try to substitute the pattern with space then the sed will replace the character or pattern with space,... (1 Reply)
Discussion started by: frozensmilz
1 Replies

8. Shell Programming and Scripting

How to make a long print string to shotcut form in perl?

print "1.readfromfile\n2.add_ex1(4,5)\n3.add_ex2(11,5)\n4.add_ex3(9,3)\n5.add_ex4(91,4)\n"; How to do it in this form: print "1.readfromfile\n 2.add_ex1(4,5)\n 3.add_ex2(11,5)\n 4.add_ex3(9,3)\n 5.add_ex4(91,4)\n"; (3 Replies)
Discussion started by: cola
3 Replies

9. Shell Programming and Scripting

convert one form of xml data to other

I would like to convert one form of xml tag data to another <DescriptionList> <DescriptionExt language="en" shortDesc="ITALIAN SAUSAGE SUB" longDesc="" sizeDesc="" smallImage="Pictures\sub-italian-sausage.png" largeImage="" forceImageUpdate="yes" /> ... (1 Reply)
Discussion started by: saisus
1 Replies

10. UNIX for Advanced & Expert Users

Changing Unix form to Microsoft Word form to be able to email it to someone.

Please someone I need information on how to change a Unix form/document into a microsoft word document in order to be emailed to another company. Please help ASAP. Thankyou :confused: (8 Replies)
Discussion started by: Cheraunm
8 Replies
Login or Register to Ask a Question