Page 1 of 1

Replace only within special part of each file

Posted: Wed Jun 08, 2005 7:55 pm
by nickgust
Hello all,

I have used AFR for a while, but I am stumped on this one. I have problem. I have a large number of files, often several thousans of them, where I need to replace a random string inside to code. Where the string is can ve figured out by the text before and after it, but what then need to do is replace spaces " " with dashes "-". Assume that the code is

Code: Select all

<!--#include virtual="/sub/search and save.asp" -->


The "search and save" part is randone and will not repeat itself in the files at all. So what I need to do is first find the string between "#include virtual="/sub/" and ".asp" -->" and then do a replace on the spaces and turn them into dashes.

Ii this possible? I figured if any app I have ever seen can, this is the one.

Posted: Wed Jun 08, 2005 8:44 pm
by Abacre
Hi Nick,

You are right it's possible to do with AFR.
Read the similar case.

So:
Start the program. Go to main menu - Action - Options - "Batch
replace" check on the options:
Replace until found is ON
Modifier S is OFF.
Modifier G is OFF.
check ON: "Replace until found".

Press OK.

In main window go to Batch replace tab.
Check on "Use regular expressions".
Then fill the grid:
Search for:
#include virtual="/sub/(.+) (.+)\.asp

Replace with:
#include virtual="/sub/$1_$2.asp

That's all. You may press now Execute button.
I verified it perfectly works. The program produced the resulting text
as above.

But it your case I would also include <!-- --> into search scope
so the final pair should be:
Search for:
(<!--.*#include virtual="/sub/.+) (.+\.asp.*-->)
Replace with:
$1_$2

I verified it worked too.

Posted: Thu Jun 09, 2005 1:16 am
by nickgust
Roman,

ok I will toss in another thing to make it worse. on top of everything the number of words in my search string varies from 2 to maybe 5. I need to be flexible and still get "-" between each word.

Sorry I forgot to tell you before.

Posted: Thu Jun 09, 2005 11:20 am
by Abacre
Nick,

Number of words is not a problem. There are maybe any number of words.
Modifier S in OFF position means that these words should be on one
line (for one URL).

But I should add a small correction here, you said you need to insert "-" (minus
sign). But I thought you need to insert underscore "_".
So in my previous examples use "-" instead of "_".
1st example Replace with:
#include virtual="/sub/$1-$2.asp

2nd example Replace with:
$1-$2

Please try it. Does it work?

Posted: Thu Jun 09, 2005 11:23 pm
by nickgust
Sorry to drag this out, but I don't have (or can't find) the "Replace until found" option anywhere. I am using version 2.0. Actually I updated with the new version per your email but it never changed the version in the "about" section. WHat am I missing?

Posted: Fri Jun 10, 2005 12:01 pm
by Abacre
Yes, this options "Replace until found" appears only since v2.3.

Try the following:

Download the latest version of the program:
http://www.abacre.com/download/afrexe.zip

This is only updated EXE file. You need to extract executable file from
zip archive into folder where the program is installed. So you will
replace old executable file by this new one.

Posted: Fri Jun 10, 2005 9:55 pm
by nickgust
Perfect. I love this tool :)

Many thanks Roman.