| Author |
Problem replacing a line AWK, SED or GREP
|
jhon masco
Ranch Hand
Joined: May 13, 2010
Posts: 93
|
|
I need to replace a complete line in a text file.
The line than i need replace has this aspect:
Yes, it is a piece of code. I want replace this line with other line.
From other file i am obtaining a list of ip address, then i concatened these in a variable , example:
I do that because the ip address are incrementing frequently.
After that i build other variable like:
Therefore i would love be able to do something as:
but i am having problem get the line from the code in a variable. If i do:
it find the full line! that is very good but...when i want to put it in a variable like:
not work!
Then I tried with other option as:
or
in all cases the console say: syntax error
I need to know how i can replace a full line. I did think this would be easy!!! but No.
The good part of this is that I am learning a lot
Please Help!
Muchas Gracias
|
 |
jhon masco
Ranch Hand
Joined: May 13, 2010
Posts: 93
|
|
Solved!!!
i used:
First step i created a new file (textFile.txt) and write the new text that i want to write in the original file.
then:
it will find the lline pattern but NOT overwrite it, is just write the new line in the next line, therefore you will be see 2 lines, the old and new one:
is to say 2 IF consecutive.
then after that i apllied this sentence:
and that is all!!
|
 |
saahil gupta
Ranch Hand
Joined: Dec 26, 2011
Posts: 64
|
|
|
Thanks for this Great Help
|
 |
jhon masco
Ranch Hand
Joined: May 13, 2010
Posts: 93
|
|
I have found a mistake in my solution.
When i run this line of code, it delete both lines , the old and the new
then i did must to put this before:
with this line i get the line number of the old line (original line)
then , i delete that line with
and ready!
Gracias
|
 |
 |
|
|
subject: Problem replacing a line AWK, SED or GREP
|
|
|