From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18761 invoked by alias); 15 Jun 2016 17:12:22 -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: 21665 Received: (qmail 24881 invoked from network); 15 Jun 2016 17:12:21 -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,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=5YpP5RkdSWBDSNAVjP6Kb90nElWIUWmLvib3ld1ZLv4=; b=MJMXMzdHyWRRTDgyuVn8/lCT+dxufJhxVAMURzAk/tF5BknPMgNxOW385ZuLupzbYc MlA3GhYZ4X6BWUpRDf06UwPmSF2SX+uwGzz53ulPlLu/t+Z7lHX+Rl9iNRNqN+0rlYmu 9XnzVzbWUp4zpiW5Mqltd+nykda1ZDrDLQVzXzl8mclN+MDFWczkcfaObnryLOnFEWfy MhJ0lejTu9AjgXHA1/hFHUeCH9XIfGMeWtcEBIaHsxWyF7DOa/eaFIzWaS+xFG0C3W0F W4ExNRx7v6rDczJQP58yRcZ4Zsglkd8vO0yQMls4Uh2oMjHnlG5i+cPnr36fUIJzhej+ yvEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=5YpP5RkdSWBDSNAVjP6Kb90nElWIUWmLvib3ld1ZLv4=; b=hDrTLpO33/lztIL+IKyevt2K+SaB1fFcpeLn/dX9kft1e6Hi/dvHYTWAuO5IEtK0H1 8o54FCosiTkUjXo3Yv7M7DXEfGKvfddrhFnIElrf/xpYjvb09/MOEse3CcHhGaRkJEHf iZBet92BXd+Y8If2YuXMPla+3zSF+smOAUiAutGd3bkt53cfb2MOLKEpHNBp0bZKRywa ymvIau3HMzEdX/gFpu0m4y1iCK2nmsvjZ6IK2aA9avf+hIb5uru5h5wu/eHPAEU7wy2d 17oXjueZ9npAjB5rotBt2iC1vuGSECJHy3d+bMbcAkK7ygY9lEYHiCXZKbEtHyGNB97U d2dw== X-Gm-Message-State: ALyK8tKBNdyytEQRrzPt75tePLO91uwSx4YERETwpmpQ3EExfo/v1qXehb4oUJM2l4rArw== X-Received: by 10.98.67.7 with SMTP id q7mr4947371pfa.70.1466010737978; Wed, 15 Jun 2016 10:12:17 -0700 (PDT) From: Bart Schaefer Message-Id: <160615101239.ZM21280@torch.brasslantern.com> Date: Wed, 15 Jun 2016 10:12:39 -0700 In-Reply-To: Comments: In reply to Sebastian Gniazdowski "Feature request: two level sorting" (Jun 15, 7:13am) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: Feature request: two level sorting MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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.