wood burning stoves 2.0*
The moose likes Linux / UNIX and the fly likes Problem replacing a line AWK, SED or GREP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Problem replacing a line AWK, SED or GREP" Watch "Problem replacing a line AWK, SED or GREP" New topic
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!!

Ifteqar Ald
Ranch Hand

Joined: Dec 26, 2011
Posts: 73
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
 
Consider Paul's rocket mass heater.
 
subject: Problem replacing a line AWK, SED or GREP
 
Similar Threads
Search on a string
parsing numeric & special characters
Automate Stripping of a record
help on awk or sed
Use of SED in shell scripts