From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5816 invoked by alias); 15 Jun 2016 18:25:13 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21667 Received: (qmail 13330 invoked from network); 15 Jun 2016 18:25:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=noG5/6OeW+D5l6mz0rbKZAeGCV6JpjaQ8KazipvRnXA=; b=fSAamb5hpWjnnpo7W5xS3gd4NDUCBIJWGFAHIP90SseDxSb9COhGh5zaxlWE9dDDQV 894PZPJgi17GKS2KxVIGYLGQsj02ccbiK+OtPRmAdett4ykygmeSaNao+hpKmYUOn8Fw 6ZThQG7mLieUVbuV+w0OJ8hsm1JPNCOElxcZGu6q+cqrUI8JSx6gK+Asv8McXWcB2A03 WdhZgr+4ZtSG1OuuZvuAZeRf04lnAKVmKBdD1mPb3daSFSo4gkp388udgpAEbb3Baw5I BS7xgx6lsxBPcDJDLyY6XHQ7+aCZRoGAc9o4nc/XLoZbGfRwxEMm5VSybuSlBTNwRAHR 7tRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=noG5/6OeW+D5l6mz0rbKZAeGCV6JpjaQ8KazipvRnXA=; b=HmPiODeqkQ6XKHburoAYlbfhUJMuzX7g29FGOHXVghzRh87yqVqnTAdcG+bNO8n0gY U2rwBEpBM44aR0n4WNrATikI7Jx+1b10TEeAJWNNWLrLIDZsTCyFXdiyavitBxlcLBp0 10sTsrv7wmTKwqhmcbwFva4SH8QC001Sm3XN8ekpFVwBlTLJmPajupZ/Vc6CE+HZI7R/ 0vhy97Y//J/Gm7DOFKViv9pQyXWi1vjXaYtL4dwn1XBfQufPGTYMSPAqF/Pfy2Xjwo4w uiBBlhQC9TQRXREdsVEncaypdRQNB6gLQrY2dvXmc/O8zf6Ke+LXWxu/5h7oPxrCbDxh Wekg== X-Gm-Message-State: ALyK8tJUJCoOpSWEvwXf8cVyp1Rl7OPBDMLJ8qmM7Xlrvs0bOQkiYck9CEp1GFvX9NXAPefgVOs0RpPFU5mZ7A== X-Received: by 10.140.227.72 with SMTP id x69mr161682qhb.70.1466015107280; Wed, 15 Jun 2016 11:25:07 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <160615101239.ZM21280@torch.brasslantern.com> References: <160615101239.ZM21280@torch.brasslantern.com> From: Mikael Magnusson Date: Wed, 15 Jun 2016 20:25:06 +0200 Message-ID: Subject: Re: Feature request: two level sorting To: Bart Schaefer Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 On Wed, Jun 15, 2016 at 7:12 PM, Bart Schaefer wrote: > On Jun 15, 7:13am, Sebastian Gniazdowski wrote: > } > } # print -rl -- ${(o)files[@]} > } aaa-A > } aab-B > } aac-A > } aad-C > } > } when sorted with grouping on A, this will be: > } > } aaa-A > } aac-A > } aab-B > } aad-C > > In a follow-on message you compare this to SQL GROUP BY, but you're > conveniently ignoring that GROUP BY works on rows of data in columms > whereas here you're asking for something that works on arrays of > strings. > > "Feature request: A one-line parameter expansion that converts an > array to a two-dimensional array by parsing with a pattern match, > sorts the 2d array on one axis using multiple values of the other > axis, and then reassembles the original one-dimensional array > elements again in the new ordering." > > Can you even suggest a syntax for this that wouldn't look worse than > the "for" loop you already wrote? > > } **The thing is** that it is easy to provide group names in separate > } array: > } > } # groups=( "${files[@]//(#b)*([A-Z])/$match[1]}" ) > > OK, let's examine that for a second. What can't easily be done in the > general case might be easily done in the specific. Can you choose a > delimiter of some kind that will never appear in $match[1] ? Let's > try ":" for this example. > > groups=( "${files[@]//(#b)*([A-Z])(#m)/${match[1]}:$MATCH}" ) > > Now: > > print -rl -- "${(@)${(@o)groups}#*:}" > > And there you go. It can even be written without the extra array: > > print -rl -- "${(@)${(@o)${files[@]//(#b)*([A-Z])(#m)/${match[1]}:$MATCH}}#*:}" > > But it would be horrible to try to make a generic sorting flag that > can be passed the pattern plus the fields on which to group plus the > sort order to apply to the result. Can we do what the oe:: flag does for globbing? Ie, pass each element to a custom code snippet that transforms it arbitrarily, and sort on the output. -- Mikael Magnusson