Incrementing the string of numbers by one

General discussions about Advanced Find and Replace
Post Reply
ajivani
Posts: 10
Joined: Mon Apr 18, 2005 8:11 pm

Incrementing the string of numbers by one

Post by ajivani » Thu Sep 07, 2006 5:29 pm

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

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Thu Sep 07, 2006 6:11 pm

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

?
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

ajivani
Posts: 10
Joined: Mon Apr 18, 2005 8:11 pm

Post by ajivani » Thu Sep 07, 2006 6:15 pm

It will be

LOAN.NUMBER|98573750

Basically it should increment by 1

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Thu Sep 07, 2006 6:28 pm

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.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

ajivani
Posts: 10
Joined: Mon Apr 18, 2005 8:11 pm

Additional Similar Batch Replace

Post by ajivani » Fri Sep 08, 2006 6:07 pm

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?

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Fri Sep 08, 2006 7:28 pm

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.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

ajivani
Posts: 10
Joined: Mon Apr 18, 2005 8:11 pm

Post by ajivani » Tue Sep 12, 2006 5:17 am

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

Abacre
Site Admin
Posts: 1201
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Tue Sep 12, 2006 6:37 am

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.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests