Question : match multiple lines in a file

Hi,

I have the following situation:

---start of file.txt---
text text text text text text text text text text text text text text text text
 text text text text text text text text text text text text text text text text text text text text text text
 text text text text text text text text text
start object_1
  id="1";
 name="xxx";
end object_1
 text text text text text text text text text text text text text
 text text text text text text text text text
start object_2
  id="2";
 name="xxx";
end object_2
 text text text text text text text text text text text text text
 text text text text text text text text text
---end of file.txt---

I need to match in the file.txt structures like:
start object_x
  id="(.*)";
 name="xxx";
end object_x

After this I will have a list of IDs (maybe in a file, line by line).

Then foreach ID I will get the 'name' from a database and I will need to replace it in the file ( e.g. 1 -> abc, 2->def) and I will have the new file.txt like:

---start of new_file.txt---
text text text text text text text text text text text text text text text text
 text text text text text text text text text text text text text text text text text text text text text text
 text text text text text text text text text
start object_1
  id="1";
 name="abc";
end object_1
 text text text text text text text text text text text text text
 text text text text text text text text text
start object_2
  id="2";
 name="def";
end object_2
 text text text text text text text text text text text text text
 text text text text text text text text text
---end of new_file.txt---


Anybody has a clue :)
I already started to write sed command to match this, but I cannot match more than one line at a time...

Thanks a lot

Answer : match multiple lines in a file

It seems to be working for me
did you include the filename
perl -i -pe 'BEGIN{$/="end object_"} s/(start object_.*name=)".*?"/$1"'$NAME'"/s if /start object_.*id="'$ID'"/s' file.txt
If so, can you give me an example on which it doesn't work?
Random Solutions  
 
programming4us programming4us