Jump to content
Macro Express Forums

Find and replace macro -


Recommended Posts

I am wanting to edit text files, but I want to edit alot of files, and alot of strings in those files. So I come back to my old love Macro Express... Sadly I never really used it for much more than mouse clicks/text input.

 

So, an example of what I want to edit:

 

<subtitle_script id='47166' title='English' play_res_x='640' play_res_y='480' lang_code='enUS' lang_string='English (US)' created='2 days ago' progress_string='' status_string='Approved' wrap_style='2'><styles><style id="49922" name="PLACEHOLDERS"

<subtitle_script id='47166' I want to replace with: [script Info]^p

<style id="49922" name=" I want to replace with: Style:

 

1st Problems: For some reason, even trying to simply replace the word "play" with "apple" is not working, It is loading the file into T5 and then from there it is saving it to sample2.txt as it is supposed to :/

 

2nd Problem: How do I make wildcards as the ID 47166 is a random number depending which file I want to replace (plan to run macro on 50+ files to start with)

 

<VSETMISC:T4:Installation Path><REM2:use text file in installationPath "textanswers.txt"><TVAR2:05:04:C:\Program Files\Macro Express3\sample.txt><REM2:Do all your replaces here; this only example><TMVAR2:21:05:01:001:000:nameapple><DELAY:1><REM2:....all numbers, descending, in between; there's probably a better way...><TMVAR2:17:05:00:000:000:C:\Users\Pantho\Documents\sample2.txtT>

Set Variable %T4% to "Installation Path"
// use text file in installationPath "textanswers.txt"
Variable Set String %T5% from File: "sample.txt"
// Do all your replaces here; this only example
Replace "name" with "apple" in %T5%
Delay 1 Seconds
// ....all numbers, descending, in between; there's probably a better way...
Variable Modify String: Save %T5% to Text File

 

This is what I have found so far, from reading related topics. Any help you can with the first 2 search and replace commands would be great, then I could use those examples to finish the rest.

Link to comment
Share on other sites

First, I have to ask: What version of Macro Express are you using? Your code above looks like Macro Express 3, but this is the Macro Express Pro forum. The help you're looking for is likely going to be different depending on which version you're using..

 

 

Second, I see you set the installation path to T4, but then you don't do anything with T4. You then set T5 from sample.txt, but we don't know what sample.txt contains (I'm assuming it contains the information from the first "code box" in your post. If that is the case, I don't see any reason why this macro wouldn't be replacing the text you've specified. I just ran the macro (after changing the sample.txt and sample2.txt locations to my desktop for my convenience).

 

Here are my results, before and after:

Before

<subtitle_script id='47166' title='English' play_res_x='640' play_res_y='480' lang_code='enUS' lang_string='English (US)' created='2 days ago' progress_string='' status_string='Approved' wrap_style='2'><styles><style id="49922" name="PLACEHOLDERS"

After

<subtitle_script id='47166' title='English' play_res_x='640' play_res_y='480' lang_code='enUS' lang_string='English (US)' created='2 days ago' progress_string='' status_string='Approved' wrap_style='2'><styles><style id="49922" apple="PLACEHOLDERS"

 

btw, I did this in ME3, based on the code provided.

 

Edit - Time: 8:07 Mtn

In the interest of being thorough, I modified the macro to perform exactly the changes you asked specifically about. The macro had no trouble making these changes:

 

<subtitle_script id='47166' was changed to [script Info]^p

and

<style id="49922" name=" was changed to Style:

 

Well, that's not entirely true. There was a brief moment when the second one didn't work, but that was before I realized that the word "name" had already been changed to "apple", which led to a whole other confusion. Anyway, I disabled the command that changed "name" to "apple" and the macro worked fine. See examples of before and after below.

 

The question remains: do you want name changed to apple? or do you want <style id="49922" name=" changed to Style:? Or do you want some other combination altogether?

 

Before

<subtitle_script id='47166' title='English' play_res_x='640' play_res_y='480' lang_code='enUS' lang_string='English (US)' created='2 days ago' progress_string='' status_string='Approved' wrap_style='2'><styles><style id="49922" name="PLACEHOLDERS"

After

[Script info]^p title='English' play_res_x='640' play_res_y='480' lang_code='enUS' lang_string='English (US)' created='2 days ago' progress_string='' status_string='Approved' wrap_style='2'><styles>Style:PLACEHOLDERS"

Link to comment
Share on other sites

First, I have to ask: What version of Macro Express are you using? Your code above looks like Macro Express 3, but this is the Macro Express Pro forum. The help you're looking for is likely going to be different depending on which version you're using..

 

 

Second, I see you set the installation path to T4, but then you don't do anything with T4. You then set T5 from sample.txt, but we don't know what sample.txt contains (I'm assuming it contains the information from the first "code box" in your post. If that is the case, I don't see any reason why this macro wouldn't be replacing the text you've specified. I just ran the macro (after changing the sample.txt and sample2.txt locations to my desktop for my convenience).

 

Here are my results, before and after:

Before

 

After

 

 

btw, I did this in ME3, based on the code provided.

 

Edit - Time: 8:07 Mtn

In the interest of being thorough, I modified the macro to perform exactly the changes you asked specifically about. The macro had no trouble making these changes:

 

<subtitle_script id='47166' was changed to [script Info]^p

and

<style id="49922" name=" was changed to Style:

 

Well, that's not entirely true. There was a brief moment when the second one didn't work, but that was before I realized that the word "name" had already been changed to "apple", which led to a whole other confusion. Anyway, I disabled the command that changed "name" to "apple" and the macro worked fine. See examples of before and after below.

 

The question remains: do you want name changed to apple? or do you want <style id="49922" name=" changed to Style:? Or do you want some other combination altogether?

 

Before

CODE
<subtitle_script id='47166' title='English' play_res_x='640' play_res_y='480' lang_code='enUS' lang_string='English (US)' created='2 days ago' progress_string='' status_string='Approved' wrap_style='2'><styles><style id="49922" name="PLACEHOLDERS"[/code]

After

[Script info]^p title='English' play_res_x='640' play_res_y='480' lang_code='enUS' lang_string='English (US)' created='2 days ago' progress_string='' status_string='Approved' wrap_style='2'><styles>Style:PLACEHOLDERS"

 

The T4 variable was left in by mistake, ignore it heh.

The name and apple part where simple examples I used for testing.

 

The macro above will not work for me, and it's starting to annoy me. I simply cannot understand why that isn't working...

For the time being I made a MSoffice macro, but a ME macro would be much more efficient.

 

Also, if it did work not sure how to make the ID a wildcard.

Link to comment
Share on other sites

The T4 variable was left in by mistake, ignore it heh.

The name and apple part where simple examples I used for testing.

 

The macro above will not work for me, and it's starting to annoy me. I simply cannot understand why that isn't working...

For the time being I made a MSoffice macro, but a ME macro would be much more efficient.

 

Also, if it did work not sure how to make the ID a wildcard.

Hmmm...

 

Make sure your "Replace" commands don't have any spaces before or after the text you want changed. That is the number one problem I have when using this particular command. Those invisible spaces will throw a monkey wrench into the gears, making a mess of an otherwise perfect macro.

 

If that doesn't work, try my code (it's virtually identical to yours). My sample.txt is on my desktop, so you'll want to either change the directory in the macro, or put your sample.txt on your desktop.

 

<REM2:use text file in installationPath "textanswers.txt"><TVAR2:05:04:C:\Documents and Settings\z051940\Desktop\sample.txt><REM2:Do all your replaces here; this only example><TMVAR2:21:05:01:001:000:<subtitle_script id='47166'[Script info]^p><TMVAR2:21:05:01:001:000:<style id="49922" name="Style:><DELAY:1><REM2:....all numbers, descending, in between; there's probably a better way...><TMVAR2:17:05:00:000:000:C:\Documents and Settings\z051940\Desktop\sample2.txtT>

 

As far as the wildcard issue goes, I have to say I'm not completely certain what it is you need to do. Are you calling it a wildcard because it will be different each time the macro runs, and you need the macro to recognize the text that needs to change regardless of what numbers are inside it? If so, it is possible, though it will take a bit more logical code to make the macro work.

 

I'll take a shot at it and post my results when I have them (at work right now, so it may take a little while).

Link to comment
Share on other sites

As far as the wildcard issue goes, I have to say I'm not completely certain what it is you need to do. Are you calling it a wildcard

because it will be different each time the macro runs, and you need the macro to recognize the text that needs to change regardless of

what numbers are inside it? If so, it is possible, though it will take a bit more logical code to make the macro work.

 

I'll take a shot at it and post my results when I have them (at work right now, so it may take a little while).

Assuming I understood what you wanted, the answer was not too difficult to figure out. As I mentioned, it did require a little bit of extra logic

which, in turn, required quite a few extra lines of code, but nothing too extreme. The following code makes several assumptions about the text

you'll be modifying with it.

 

1. It assumes the wildcards will always fall after style id=" or script id='

2. It assumes that script id=' will always be followed by title=

and

3. It assumes that style id=" will always be followed by name=

 

 

Where you see N1 modified by +11 and +10, those numbers are derived by the number of characters of script id=' and style id=",

respectively.

 

Finally, because the original request to change

 

<subtitle_script id='47166' to [script Info]^p

and

<style id="49922" name=" to Style:

 

The Replace commands completely removed the "wildcards", leaving there no reason to even care about them... so in order to be

thorough (I like thoroughness), I went ahead and added them back in so the results should end up looking like this:

 

<subtitle_script id='47166' to [script Info]^p 47166

and

<style id="49922" name=" to Style: 49922

 

Here's the code. Let us know if you're still having issues (though we really might want to move it over to the ME3 forum).

 

<REM2:use text file in installationPath "textanswers.txt"><TVAR2:05:04:C:\Documents and Settings\z051940\Desktop\sample.txt><REM2:The following code will isolate the "script id" wildcards><IVAR2:01:13:5:script id='><NMVAR:01:01:1:0000001:2:0000011><IVAR2:02:13:5:title='><NMVAR:02:03:1:0000002:1:0000001><TMVAR2:10:06:05:N01:N03:><TMVAR2:21:06:01:001:000:'><TMVAR2:01:06:00:000:000:><REM2:The following code will isolate the "style id" wildcards><IVAR2:01:13:5:style id="><NMVAR:01:01:1:0000001:2:0000010><IVAR2:02:13:5:name="><NMVAR:02:03:1:0000002:1:0000001><TMVAR2:10:07:05:N01:N03:><TMVAR2:21:07:01:001:000:"><TMVAR2:01:07:00:000:000:><REM2:Do all your replaces here; this only example><TMVAR2:21:05:01:001:000:<subtitle_script id='%T6%'[Script info]^p %T6%><TMVAR2:21:05:01:001:000:<style id="%T7%" name="Style: %T7%><DELAY:1><REM2:....all numbers, descending, in between; there's probably a better way...><TMVAR2:17:05:00:000:000:C:\Documents and Settings\z051940\Desktop\sample2.txtT>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...