View Full Version : Replace in File query
pyang
06-28-2004, 12:16 AM
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
kinook
06-28-2004, 08:43 AM
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.
pyang
06-28-2004, 09:46 PM
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.
kinook
06-28-2004, 10:17 PM
Typo in there (missing alternation operator). The attachment has been updated with a fix.
pyang
06-28-2004, 10:31 PM
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.
kinook
06-28-2004, 10:39 PM
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.
pyang
06-28-2004, 11:08 PM
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.
pyang
06-29-2004, 03:08 AM
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.
vBulletin® v3.8.11, Copyright ©2000-2024, vBulletin Solutions Inc.