- At 5/21/2013 03:59 PM, Flo wrote:
>I'm dealing with a list like...

Nothing canned but how about this:

>

>3 Carla

>23 Bertha

>110 Anthony

>2245 Dorothy

>99 Edward

>

>The job: Sort that list on the leading numbers and make each name start at the same position. That is, the result should be...

>

>···3 Carla

>··23 Bertha

>··99 Edward

>·110 Anthony

>2245 Dorothy

>

>Has anyone got an efficient solution for that job?

^!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

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

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

Discard all leading zeros greater than the field width

Sort the doc

Replace leading zeros with spaces

I haven't tested it but it should work. (right!)

I generalized it a bit to allow for leading white space.

Reduce or add the number of leading zeros to handle your data

The removal of the leading zeros could be put into a loop but why bother?

HTH

Art - 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!"