Results 1 to 4 of 4
Hi,
I have a text file which is split into various sections with different names and those sections have the same variables and values defined. eg.
[section 1]
ipaddr=192.168.1.1
user=user1
...
- 10-30-2009 #1Just Joined!
- Join Date
- Aug 2009
- Location
- Mumbai, India
- Posts
- 74
Specific find and replace
Hi,
I have a text file which is split into various sections with different names and those sections have the same variables and values defined. eg.
[section 1]
ipaddr=192.168.1.1
user=user1
passwd=password1
[variable 2]
ipaddr=192.168.1.1
user=user2
passwd=password2
.... and so on...
I am looking for a command which would help me replace a specific string like the ipaddr value in a specific section - say the second section coz i need to integrate it into a bash script. I don't wanna do a global find and replace.
Assistance appreciated.
--Syd
- 10-30-2009 #2Just Joined!
- Join Date
- Jan 2007
- Location
- Tamil Nadu, India
- Posts
- 18
If you unique sections, then you can very well use 'sed' command to replace the contents under a particular section.
- 10-30-2009 #3Linux User
- Join Date
- Aug 2006
- Posts
- 458
see here (example 3) for similar example
- 11-04-2009 #4Just Joined!
- Join Date
- Aug 2009
- Location
- Mumbai, India
- Posts
- 74
Hi,
Thanx for pointing out to an URL. Of course I'll have to brush up on my knowledge of sed since the code mentioned in the URL there did not make much sense to me.
From whatever little bit i managed to understand i assume the code groups multiple lines of the section and assists with search and replace. In the file that I have, not all the sections are of equal length. I mean some initial sections span 10-15 lines and the latter ones 4 - 5 lines but the sections on which i want the search and replace to work are of similar length.Would the code work in this scenario as well?
Meantime since the code helps me get started somewhere atleast, I'll get on with understanding sed. Thanx...
--Syd


Reply With Quote

