Addition to the last numbers

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Kiroptus
Posts: 2
Joined: Tue Dec 04, 2012 1:36 pm

Addition to the last numbers

Post by Kiroptus »

Hello, sorry for my noobness about regular expressions but I need something as simple as just adding +25 to the final number. Its a big line but only the final 3 numbers that matter:

Example:

563474.7900 9698470.1500 4 MNH152.06@R00357
563415.4200 9698332.9000 3 MNH152.06@R00357
563365.9800 9698192.5000 2 MNH152.06@R00357
563315.6300 9698050.6800 1 MNH152.06@R00357

needs to become

563474.7900 9698470.1500 4 MNH152.06@R00382
563415.4200 9698332.9000 3 MNH152.06@R00382
563365.9800 9698192.5000 2 MNH152.06@R00382
563315.6300 9698050.6800 1 MNH152.06@R00382



There SO many files with that behavior, if anyone could help to find an expression to just replace the last 3 numbers (column 85, 86, 87) with +25 it would be extremely appreciated.
ben_josephs
Posts: 2457
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Unfortunately, it isn't simple. Regular expressions can't count or add: all they know about is uninterpreted characters. In principle you can do this, but not with a single search-and-replace operation. It would be very tedious and would require many separate and different search-and-replace operations.

This is a job for a script in a suitable language, such as Perl, Python, Ruby, Tcl, ECMAscript or Lua. TextPad doesn't support scripts.
Kiroptus
Posts: 2
Joined: Tue Dec 04, 2012 1:36 pm

Post by Kiroptus »

Aw thats too bad, I thought it looked so simple. Thanks for the reply I will look into other ways of doing it.
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

If you have a spreadsheet program, that can handle more than 65K lines, it's easy enough with a Right Function.

Copy into the spreadsheet, write the Function, drag it down, copy and paste back into TextPad.
(2[Bb]|[^2].|.[^Bb])

That is the question.
User avatar
jeffy
Posts: 323
Joined: Mon Mar 03, 2003 9:04 am
Location: Philadelphia

Re: Addition to the last numbers

Post by jeffy »

Kiroptus wrote:If anyone could help to find an expression to just replace the last 3 numbers (column 85, 86, 87) with +25 it would be extremely appreciated.
You could do this easily in PhraseExpress:

Code: Select all

- zProcessAllLines:
{#LOOP zProcessLine -count {#INPUT -head How many lines to process? -single}}
- zProcessLine:
{#RIGHT -count 85}{#SHIFT {#END}}{#CLIPBOARD -copy}{#CALC {#CLIPBOARD -paste} + 25 -round 0 -thousands none}{#RIGHT}
Didn't actually try this, but you get the idea. As far as left-0-padding numbers that total less than 100, I think the CALC function may have some parameters to do so. And if not, the CALC function output could be inserted into a COND (conditional) phrase, which would certainly do the trick.
User avatar
jeffy
Posts: 323
Joined: Mon Mar 03, 2003 9:04 am
Location: Philadelphia

Post by jeffy »

Actually, if it truly is the last three characters, then this is better:

Code: Select all

- zProcessLine: 
{#END}{#SHIFT {#LEFT -count 3}}{#CLIPBOARD -copy}{#CALC {#CLIPBOARD -paste} + 25 -round 0 -thousands none}{#RIGHT} 
Post Reply