I'm trying to write a script that updates globals in other scripts. I've tried using "filefilter", but I need it to find the string, and then replace that whole line with the new string, not just the matched string. I've also tried using file read/write. The only way I could figure out how to write to a specific line number was, for every line, read a line of the original script, write it to the new script if it weren't a match, otherwise write the new line. However, in doing this Stata evaluated all of my macros (i.e. blanked them out in the new file).
My next approach would be to combine the two approaches where the "file read" first looks through the script where it matches a partial line, and then passes the whole line as the string to replace argument in the "filefilter". However, I think I'll still be limited by macro substitution (e.g. I'm fine if the line I'm searching for and the replacement line have no macros, but otherwise not necessarily). Is there 1) an easier, more efficient way of doing what I'm trying to do and 2) is there a way to turn off macro substitution for an entire line?
My next approach would be to combine the two approaches where the "file read" first looks through the script where it matches a partial line, and then passes the whole line as the string to replace argument in the "filefilter". However, I think I'll still be limited by macro substitution (e.g. I'm fine if the line I'm searching for and the replacement line have no macros, but otherwise not necessarily). Is there 1) an easier, more efficient way of doing what I'm trying to do and 2) is there a way to turn off macro substitution for an entire line?
Comment