Replacing a pattern using variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing a pattern using variable?
# 1  
Old 04-30-2009
CPU & Memory Replacing a pattern using variable?

ip1="xxx"
ip2="bbb"

sed 's/$ip1/$ip2/g'
# 2  
Old 04-30-2009
sed s/"$ip1"/"$ip2"/g filename
# 3  
Old 04-30-2009
Hi,
Double quote doesn't work but single quote works fine...........

Thank you.......
# 4  
Old 04-30-2009
no quote also work fine

Code:
 
TEST>echo "xxx" |sed s/$ip1/$ip2/g
bbb

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern replacing

Hi, I have a text file with lots of text (strings,numbers,special characters etc). I am trying to replace any occurrence of these strings : 90% 91% 92% .... 100% I want to replace them with : "90%" "91%" "92%" .... "100%" I am now using 10 sed commands for replacement but I... (12 Replies)
Discussion started by: ctrld
12 Replies

2. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

3. Shell Programming and Scripting

Replacing a pattern in different cases in different columns with a single pattern

Hi All I am having pipe seperated inputs like Adam|PeteR|Josh|PEter Nick|Rave|Simon|Paul Steve|smith|PETER|Josh Andrew|Daniel|StAlin|peter Rick|PETer|ADam|RAVE i want to repleace all the occurrence of peter (in any case pattern PeteR,PEter,PETER,peter,PETer) with Peter so that output... (5 Replies)
Discussion started by: sudeep.id
5 Replies

4. Shell Programming and Scripting

replacing pattern

hi, I want to do replacing of some pattern by using sed. pattern : " white space / to white space / please help -bhrat (3 Replies)
Discussion started by: bhrat kapoor
3 Replies

5. Shell Programming and Scripting

Replacing pattern

Hi, I have a file which contains the below data. I want to search for a pattern server="http://bushby.mis.amat.com:12440" and remove it from the file. Please let me know how can i do this. <Object name="reverse-proxy-/endeavour/"> ObjectType fn="http-client-config" timeout="1800"... (6 Replies)
Discussion started by: Krrishv
6 Replies

6. Shell Programming and Scripting

Replacing pattern

Hi, I have a file which contains the below data. I want to change pattern to correct format. # tail -1 test.log | awk '{print $8}' 10/09/23 # I want the format to be 23/09/10 (5 Replies)
Discussion started by: nareshkumar522
5 Replies

7. UNIX for Dummies Questions & Answers

Replacing between pattern

Hi all, I been searching the forum for a few hours now and can't find exactly what I need to replace text between two patterns. Below is what I want to accomplish /* Any text between these to sympols */ changed to.... /* This will be the new text to change */ ..and I'm... (3 Replies)
Discussion started by: Pauky
3 Replies

8. Shell Programming and Scripting

Need help in sed command ( Replacing a pattern inside a file with a variable value )

Hello, The following sed command is giving error sed: -e expression #1, char 13: unknown option to `s' The sed command is echo "//-----" | sed "s/\/\/---*/$parChk/g" where parChk="//---ee-" How can i print the variable value from sed command ? And is it possible to replace a... (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Shell Programming and Scripting

Replacing a pattern in a line

Hi, I need to replace an input IP address to an existing IP addresses. Source input line is as follows: -------------------- RequestURI := "sip: 123.1.1.1"; input IP = 124.10.3.4 My output should be Request URI := "sip: 124.10.3.4"; I have written the code as follows: $line =~... (1 Reply)
Discussion started by: gyana_cboy
1 Replies

10. Shell Programming and Scripting

Replacing pattern in variable

My String variable is holding value as - abc"def I want to replce " with \" I tried with awk : echo $var | awk '{gsub(/"/,"\"");print}' and I am getting an error, `)' is not expected. (1 Reply)
Discussion started by: videsh77
1 Replies
Login or Register to Ask a Question