Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Feature request: two level sorting
- X-seq: zsh-users 21665
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Feature request: two level sorting
- Date: Wed, 15 Jun 2016 10:12:39 -0700
- 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==
- In-reply-to: <CAKc7PVAsLwNVP0vjTvBebP5u+Ahe03yXaWxkvytOx4EPkN4V9Q@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVAsLwNVP0vjTvBebP5u+Ahe03yXaWxkvytOx4EPkN4V9Q@mail.gmail.com>
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author