- --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
>

Yes, I agree with you. So we have to find the longest number and to adapt the quantifiers and the spaces to that size.

> As the number of spaces depends on the longest possible number

> there has to be a limit, but one could loop through the data first

> and look for the longest number present.

In this Group, we've seen diverse methods of finding the longest number in a list. Here's another one: It gradually increases the quantifier which is used in a Find command. Since there is certainly no number < 3 digits, it starts with 3.

In my clip, the amount of spaces to be inserted at start of lines is equal to the length of the longest number. The quantifier to be used in the second Replace command is 'spaces -1'.

So the complete clip could look like this...

^!SetHintInfo Working...

^!SetScreenUpdate Off

^!Set %dig%=3

^!Find "^\d{^%dig%}" WRS

^!IfError Skip_2

^!Inc %dig%

^!Goto Skip_-3

^!Dec %dig%

^!Set %q%=^$Calc(^%dig%-1)$

^!Replace "^" >> "^$StrFill(\x20;^%dig%)$" WARS

^!Replace "^\x20+?(.{^%q%}\d\b)" >> "$1" WARS

^!Select All

^$StrSort("^$GetSelection$";0;1;0)$

In my tests, this works automatically with ANY size of numbers. And it's pretty fast: Tested against 90,000 lines, the job is done in two seconds.

Regards,

Flo - At 5/22/2013 06:29 AM, Flo wrote:
>--- In <mailto:ntb-clips%40yahoogroups.com>ntb-clips@yahoogroups.com, Art Kocsis <artkns@...> wrote:

I guess you are having a bad day. I don't recall you being this snarky before.

>> Nothing canned but how about this:

>> ^!Replace "^\h*?\K(\d+?)(?=\h\w)" >> "000000000$1" AIRSW

>> ^!Replace "^\d*?\K(\d{10}(?=\h\w)" >> "$1" AIRSW

>> ^!Select ALL

>> ^!Toolbar "Sort Ascending"

>> ^!Replace "^000000000([1-9])" >> " $1" AIRSW

>> ^!Replace "^00000000([1-9])" >> " $1" AIRSW

>> ^!Replace "^0000000([1-9])" >> " $1" AIRSW

>> .

>> .

>> ^!Replace "^0([1-9])" >> " $1" AIRSW

>

>Thanks for your proposal! But let me point out some inconsistencies in your clip:

>> ^!Replace "^\h*?\K(\d+?)(?=\h\w)" >> "000000000$1" AIRSW

If you had read the rest of my post I specifically said it was to generalize in case there was any leading white space and I also said it was not tested. Furthermore, I went on to detail what the clip was supposed to do so that you would be able to correct any typos or other mistakes that I might have made. In particular, I said:

>

>What are you trying to match with '^\h*?'- in the beginning, all lines start

>with a number.

> Basically, prepend as many leading zeros as digits in your largest

Unfortunately, by including the "\K" the extraneous leading zeros were not discarded. That was a logic/coding mistake. Axel caught it. Apparently you did not.

>number (nine in the example for a field width of ten digits)

> Discard all leading zeros greater than the field width

>> ^!Replace "^\d*?\K(\d{10}(?=\h\w)" >> "$1" AIRSW

Yes, well it was supposed to have an effect and it does quite well if you remove the "\K"

>

>Syntax error - closing bracket missing after '{10}'. If corrected, it replaces 10 digits with the same 10 digits - that has no effect.

^!Replace "^\h*?(\d+?)(?=\h\w)" >> "000000000$1" AIRSW

^!Replace "^\d*?(\d{10})(?=\h\w)" >> "$1" AIRSW

The first statement (now) discards any leading white space and prepends 9 zeros to the first digit appearing on the line and ensures a minimum field width of ten digits. The existence of at least one digit is insured by the "+" in the first replace command.

The second replace command (now) matches the ten least significant digits and discards any higher order digits (which will all be zeros). The result will be a fixed width field of ten digits (some with leading zeros), followed by a space, which can then be sorted.

>> ^!Replace "^000000000([1-9])" >> " $1" AIRSW

No I haven't - at least once the incorrect "\K" is removed. The first replace effects ONLY the case for nine zeros followed by a single non-zero digit, replacing the nine zeros with nine spaces. (the nine spaces apparently got lost in the yahoo translation.) This will be the condition for an original line containing only a single digit.

>> ^!Replace "^00000000([1-9])" >> " $1" AIRSW

>> .

>Can't work - you've replaced all zeros with spaces already

The second replace command matches eight zeros followed by a non-zero digit which will be the case only when there were only two digits in the original line.

Similarly for the subsequent replace commands for the remaining leading zero cases.

>Even when making this work -- in the end, the lines will be (nearly) the same as before because there is no command that will stop removing one space after the other as soon as the clip has achieved the intended alignment.

Not sure what you are saying here as there was no command posted that removed spaces so what are you wanting to stop.

Axel's clip was essentially the same except he prepended spaces directly - obviating the need to replace leading zeros with spaces.

In subsequent posts you posted your current "solution" which would handle a maximum of FOUR digits and then proceeded to berate Axel for his not working with SIX digits. Your original posted test case had four digits max, Axel's post would handle up to five digits. It's not nice to criticize someone for not satisfying a hidden agenda.

In addition, your original post asked for an "efficient" solution. It did not ask for a general solution nor did it imply anything but a one-shot need. Please be more clear and consistent when asking for help.

At 5/22/2013 07:46 AM, Flo wrote:>Couldn't we agree on a Clip List Rule #1:

No we cannot. It takes a lot more time to thoroughly test a clip than someone may have or be willing to spend offering assistance. When it is clearly stated that they are not tested I, for one, would much rather have those ideas, suggestions and partial solutions than none at all. In my case I had other pressing matters and did not have the time to test my suggestion (as I so stated in the post). I thought it would help you and be appreciated. I was mistaken. In the future I will withhold such assistance.

>

>"Don't post anything to the List that hasn't been tested before!"