Page 1 of 1

Addition to the last numbers

Posted: Tue Dec 04, 2012 1:45 pm
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.

Posted: Tue Dec 04, 2012 5:43 pm
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.

Posted: Thu Dec 06, 2012 12:09 pm
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.

Posted: Mon Dec 10, 2012 6:12 pm
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.

Re: Addition to the last numbers

Posted: Thu Dec 13, 2012 4:28 am
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.

Posted: Thu Dec 13, 2012 5:02 am
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}