Page 1 of 1

Incrementing the string of numbers by one

Posted: Thu Sep 07, 2006 5:29 pm
by ajivani
I have some text files in a directory, I want to batch replace:

In each of the file I have the following text, I want to replace the loan in such a way that the last digit in the loan number is incremented by one

For example in the file that contains the loan number 98573745, after the replace it should show loan number incrementing by one

LOAN.NUMBER|98573745

After Replace

LOAN.NUMBER|98573746

Posted: Thu Sep 07, 2006 6:11 pm
by Abacre
It's possible to do with Advanced Find and Replace.
One small question.

What should be the resulting text if the load number is:
LOAN.NUMBER|98573749

will it be:
LOAN.NUMBER|98573740

or
LOAN.NUMBER|98573750

?

Posted: Thu Sep 07, 2006 6:15 pm
by ajivani
It will be

LOAN.NUMBER|98573750

Basically it should increment by 1

Posted: Thu Sep 07, 2006 6:28 pm
by Abacre
Go to main menu - Action - Options - Batch Replace
uncheck "Modifier S"
check "Modifier I"
check "Modifier M"
check "Modifier G"
check "Modifier E"

Go to Batch replace tab, check on "Use regular expressions".
Put into the grid, search for:
LOAN\.NUMBER\|(\d+)

Replace with:
LOAN.NUMBER<%=$1+1=%>

That's all I verified it works perfectly.

Additional Similar Batch Replace

Posted: Fri Sep 08, 2006 6:07 pm
by ajivani
Batch replacment for Loan.Number|12345678

Worked. Here is additional Batch replacement I am doing.

Let me know if this looks correct.

for
LOAN.PREAPP-NUMBER|901998412

I am using

LOAN.PREAPP-NUMBER<%=$1+1=%>

but somehow when I did it, my xml file got corrupted, I could not open them.

I would like to attach my xml file, is there a way I can do it?

Posted: Fri Sep 08, 2006 7:28 pm
by Abacre
One remark:
For your first example the correct Replace With expression should be:
LOAN.NUMBER|<%=$1+1=%>

In fact I forgot to put | char after NUMBER

for your second example, the correct pair is:
search for
LOAN\.PREAPP-NUMBER\|(\d+)

replace with:
LOAN.PREAPP-NUMBER|<%=$1+1=%>

So . (dot) and | are reserved chars and you should escape it with \

I think your XML files were corrupted due to incorrect regular
expressions.
Another think could be:
You should activate using Unicode.
Go to main menu - Action - Options - Advanced:
check "Handle Unicode Files" option.

Posted: Tue Sep 12, 2006 5:17 am
by ajivani
Thank you so much for your help.

One last question if the Loan.Preapp-number begins with a letter then the expression you showed me would not work correct?

What would I use if the value of the Loan.PreApp-number begins with a letter?

LOAN.PREAPP-NUMBER|R01998412

Posted: Tue Sep 12, 2006 6:37 am
by Abacre
For this case you should use:
Search for:
LOAN\.PREAPP-NUMBER\|R(\d+)

Replace with:
LOAN.PREAPP-NUMBER|R<%=$1+1=%>

Explanations:
as I already said . and | are reserved chars. So we escape these chars
with \. This escaping is only used for Search For part.

\d means any digit (Read the Syntax of regular expressions).

We use \d+ because we need it to match one or more digits (It's noted
in the Syntax of regular expressions too).

(\d+) is used because we want to put \d+ into parameter $1 which will be
used later in Replace With part.

Now in Replace with part we use <%= =%> because we need to evaluate
some expressions.

What is inside <%= =%>? Inside we have $1+1. In fact we take the parameter
$1 and increment it by 1. What is $1 parameter? As it's stated above:
$1 is \d+ which means any one or more digits (an integer number).

That's all. I hope now it will be more clear about how regular
expressions work.