Microsoft
Software
Hardware
Network
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
Can't send email in Outlook but can receive
How can I copy Contacts from one ipaq to another
How to print multiple MS WORD docs from browser
How to create a Jar file?
IPless Post Office detection for Groupwise login
annoying 'not connected' error message, dial up connection pop-ups, when i am connected via wireless network
Installing authentic windows xp (pro or home) over possible unlicensed xp version.
options for repairing unstable laptop - low level re-format?
A public folder will display in Outlook, but not Webmail
fldrclnr.dll