• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem replacing a line AWK, SED or GREP

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for this Great Help
 
jhon masco
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic