
m00t
New User
Mar 24, 2006, 12:25 PM
Post #1 of 1
(674 views)
|
|
Search and Add Help
|
Can't Post
|
|
I have a large file that I need to add additional lines into. I need to be able to search through a file for this pattern: DEFINITION "mydefinition" { and then add something like the following after the curly brace: PROPERTY "Permitted to Write" {Edit Text Length 4074 DEFAULT "dear_admin"} So... I end up with DEFINITION "mydefinition" { PROPERTY "Permitted to Write" {Edit Text Length 4074 DEFAULT "dear_admin"} The DEFINITION is preceeded by a newline and the curly brace is almost always on the following line. What is in the quotes will be different for every DEFINITION instance. There are several hundered of these I need to change and it seems the Perl is the correct way to go. A single line file reader won't work since the search string is on multiple lines. So, something like if ( $_=~ /\nDEFINITION ".+"\n{/) which is probably incorrect, won't work. Scripts that I have looked at are searching for a string and replacing. This is somewhat akin but I think the algorithm is more likely: Find the string <newline>"DEFINITION" Find the second instance of " character Find the curly brace Insert Text End find curly brace End find " End find DEFINITION Guru help is greatly appreciated. Bill
(This post was edited by m00t on Mar 27, 2006, 10:07 AM)
|