How to substitute variable in sed for special character?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to substitute variable in sed for special character?
# 8  
Old 04-29-2012
Ow, and escape the special meaning in the replacement part of the substitution command in sed..:
Code:
Dquote=ͺ
Squote='\&#$567'
Obrac='\&^986'
Cbrac='\&^745'

output:
Code:
1.hi this is ͺvinothͺ.
2.iam software &#$567engineer&#$567.
3.How is life &^986not good&^745.
4.i have used version 1.0 as the software.And yu are the first price if 1.06.wat is involved?


Last edited by Scrutinizer; 04-29-2012 at 07:32 AM..
# 9  
Old 04-29-2012
Hi,

Below is input

Code:
1.hi this is "vinoth".
2.iam software 'engineer'.
3.How is life (not good).
4.i have used version 1.0 as the software.And yu are the first price if 1.06.wat is involved?

I want below output,

Code:
1.hi this is ϔvinothϔ.
2.iam software ȷengineerȷ.
3.How is life Ƴnot goodȖ.
4.i have used version 1.0 as the software.And yu are the first price if 1.06.wat is involved?

If i find single quotes it should be replaced by ȷ,If double quotes are found any where in the file its should be replaced by ϔ.It should not print the ',"",(,and, ).

Last edited by Scrutinizer; 04-29-2012 at 07:35 AM.. Reason: CODE TAGS!!!!
# 10  
Old 04-29-2012
Code:
Dquote=ϔ Squote=ȷ Obrac=Ƴ Cbrac=Ȗ
sed "s/\"/$Dquote/g; s/'/$Squote/g; s/(/$Obrac/g; s/)/$Cbrac/g" infile

output:
Code:
1.hi this is ϔvinothϔ.
2.iam software ȷengineerȷ.
3.How is life Ƴnot goodȖ.
4.i have used version 1.0 as the software.And yu are the first price if 1.06.wat is involved?

Or simply use:
Code:
sed "s/\"/ϔ/g; s/\'/ȷ/g; s/(/Ƴ/g; s/)/Ȗ/g" infile

or:
Code:
sed "y/\"'()/ϔȷƳȖ/" infile


Last edited by Scrutinizer; 04-29-2012 at 08:17 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Substitute a character with sed

hi all, i'd like to modify a file with sed , i want to substuite a char "-" with "/" how can i do this? Thanks for all regards Francesco (16 Replies)
Discussion started by: Francesco_IT
16 Replies

2. Shell Programming and Scripting

How to handle variable with special character?

Hi Gurus, I have a requirement which needs to pass a parameter when calling the script, using this parameter to find a file name stored in master file. then read the file content. the issue is in the file name has a special character "$". don't know how to handle this. below is example: the... (10 Replies)
Discussion started by: green_k
10 Replies

3. Shell Programming and Scripting

sed add special character

Hi all I got test.test.test and need test.test\.test * I need the backslash before the last dot in the line I tried echo test.test.test | sed 's/\./\\./g' but it gives me test\.test\.test Thanks (7 Replies)
Discussion started by: stinkefisch
7 Replies

4. UNIX for Dummies Questions & Answers

Replacing special character with sed

Hi All, I have a text file that contains I1SP2 *=*=Y=M=D001D My requirement is to replace all occurrence of =* to =Z expected o/p is I1SP2 *=Z=Y=M=D001D I have tried with sed 's/=*/=Z/g' file sed 's!\=*!\=Z/g' file sed 's!\=*!\=Z!g' file sed 's!\=\*!\=Z!g' file but its not... (3 Replies)
Discussion started by: gotamp
3 Replies

5. Shell Programming and Scripting

How to replace special character using sed?

How can I replace the follong text including to number 7000? cat tmp0.txt Winston (UK) Wong I would the 7000 to replace Winston (UK) Wong. I fail with method below: sed ' s /Winston\(UK\)Wong/7000 tmp0.txt' (1 Reply)
Discussion started by: vivien_chu
1 Replies

6. Shell Programming and Scripting

how to replace the special character with another using SED

I have the replace the pattern in the file , ); to ); Could someone please help me to get this command. (2 Replies)
Discussion started by: mohan.bit
2 Replies

7. Shell Programming and Scripting

sed special character replace

I need to do the following: text in the format of: ADDRESS=abcd123:1111 - abcd123:1111 is different on every system. replace with: ADDRESS=localhost:2222 sed 's/ADDRESS=<What do I use here?>/ADDRESS=localhost:2222/g' Everything I've tried ends up with: ... (3 Replies)
Discussion started by: toor13
3 Replies

8. Shell Programming and Scripting

Decode %s Special Character in Sed

Greetings, I am doing something that I don't know if it is possible... I have a file with a line looks like this: <%s \n%s / %s \n%s \n> and I am trying to replace this line with <%s \n%s \n%s / %s \n%s \n> in Shell script with sed command... StringToReplace='%s \n%s / %s \n%s \n'... (2 Replies)
Discussion started by: wasabihowdi
2 Replies

9. UNIX for Dummies Questions & Answers

read a variable character by character, substitute characters with something else

im having trouble doing this: i have a variable with 2 characters repeating e.g. aababbbaaaababaabbaabbba is there a way i can search the variable for a's and b's and then change a's to b's and b's to a's? im guessing its like getting the 1's compliment of the string im doing this in... (2 Replies)
Discussion started by: vipervenom25
2 Replies

10. Shell Programming and Scripting

Sed-Special character replacement

Hi I want to replace ./testsed.ksh with testsed.ksh ./ is to be removed scriptnm=`sed -e 's/\.///' $0 does not work Please help (3 Replies)
Discussion started by: usshell
3 Replies
Login or Register to Ask a Question