This week's book giveaway is in the General Computing forum.
We're giving away four copies of Emmy in the Key of Code and have Aimee Lucido on-line!
See this thread for details.
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Problem replacing a line AWK, SED or GREP

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for this Great Help
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!