#1
|
|||
|
|||
Replace in File query
Hi,
I'm trying to replace 2 strings in a text file. How do i do a wild search for both the strings? Example: String1=Testing 1234 String2=blahblahblah 456 Replace with String1=Testing 0987 String2=blahblahblah 122 I've tried using: To find String1=[[^\n"]]* String2=[[^\n"]]* replace with String1=Testing 0987 String2=blahblahblah 122 pls advice. Thank you. rgds, py |
#2
|
|||
|
|||
You need to use grouping for multiple replacements. See the attached file, the Replace in File help topic, and also the Misc.bld sample for details.
|
#3
|
|||
|
|||
I've tried the above and the result is no replacements made in file.
Why is it so?? I'm actually trying to update some SQL statement in the text file. Update String SET Name='Blahblah1234' WHERE String='String1' Pls advice. Thank you. |
#4
|
|||
|
|||
Typo in there (missing alternation operator). The attachment has been updated with a fix.
|
#5
|
|||
|
|||
Ok now it shows Replacement(s) made in file. But it only update the first item with the desired vaue and the other value is blank! The whole sentence is being replaced by an empty line!
Is this method only for 2 replacements? How to go for more than 2 replacements at one time? Thank you. |
#6
|
|||
|
|||
This is the (expected) output I get for the sample:
6/28/2004 9:36:22 PM: Building project step 'Show file'... File now contains: ... String1=Testing 1234 String2=blah 456 ... 6/28/2004 9:36:23 PM: Building project step 'Replace values'... Replacement(s) made in file 6/28/2004 9:36:23 PM: Building project step 'Show file'... File now contains: ... String1=Testing 0987 String2=blah 122 ... You can have more expressions connected with the alternation operator, just make sure to match the ?n number in the replacement field as needed. See the Replace in File help topic for links to more regex reference documentation. |
#7
|
|||
|
|||
I'm getting the result with afew carriage return after each replacement.
Each time i run the script, the number of carriage return will increase. But when i run your attached script it is fine. |
#8
|
|||
|
|||
I know why mine is different from yours.
for every replacement i did it in the next line. Therefore i'm getting the additional carriage returns for the number of replacement that i've done. Thank you. |
|
|