Replacing a pattern in a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replacing a pattern in a line
# 1  
Old 11-06-2008
Question 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 =~ s/sip:.*;/sip:$RequestURI/;

After running the code i got the output as
RequestURI := "sip:124.10.3.4

In the above output ("Smilie this two charater are missing.
can you please help me to get those last two charaters.
# 2  
Old 11-09-2008
Just add them to your replacement string:

Code:
$line =~ s/sip:.*/sip:$RequestURI\";/;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

3. Shell Programming and Scripting

Replacing lines matching a multi-line pattern (sed/perl/awk)

Dear Unix Forums, I am hoping you can help me with a pattern matching problem. What am I trying to do? I want to replace multiple lines of a text file (that match a multi-line pattern) with a single line of text. These patterns can span several lines and do not always have the same number of... (10 Replies)
Discussion started by: thefang
10 Replies

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

5. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

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

7. Shell Programming and Scripting

find pattern, delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: FRM CHK 0000 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (4 Replies)
Discussion started by: nickg
4 Replies

8. UNIX for Dummies Questions & Answers

find pattern delete line with pattern and line above and line below

I have a file that will sometimes contain a pattern. The pattern is this: W/D FRM CHK 00 I want to find any lines with this pattern, delete those lines, and also delete the line above and the line below. (1 Reply)
Discussion started by: nickg
1 Replies

9. Shell Programming and Scripting

while replacing the pattern last line is last

I am using sed command to replace the pattern, i am replacing value of variable x with value of nw for a file temp2. /usr/bin/sed 's|'$x'|'$nw'|' temp2 > $file After running it my last line is getting lost. What can be reason of this? (1 Reply)
Discussion started by: dixitked
1 Replies

10. Shell Programming and Scripting

Replacing more than 1 pattern in a line

Hi, pls advise how we could make change to more than one pattern in a single line using sed.. ie: IGNORE abcd delete}}} COND IGNORE efgh}}} will yield in abcd delete}} COND IGNORE efgh}}} Pls note that IGNORE may not be in the start of line, IGNORE is intended to be... (6 Replies)
Discussion started by: Manan
6 Replies
Login or Register to Ask a Question