Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Array parameter expansion: take n-th word from array elements
- X-seq: zsh-users 22752
- From: "Nikolay Aleksandrovich Pavlov (ZyX)" <kp-pav@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: Array parameter expansion: take n-th word from array elements
- Date: Mon, 26 Jun 2017 11:49:57 +0300
- Authentication-results: mxback6o.mail.yandex.net; dkim=pass header.i=@yandex.ru
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1498466998; bh=C5LOkbfgS510SppJOkSz1wtjxaXsoL0uDeI6qaQccZI=; h=From:To:In-Reply-To:References:Subject:Message-Id:Date; b=hQgVq/U200sOcMYQiYZkBGTYSACk0P8gw10fXfD+0zExNx2oS2gCLF+JCJ0qdTpp1 VzLKXOcxSJV8OHasFTtS+gKrjjvZbQWoqheeHja6dEDIVqELnRlFV+Ndg6L+szL62E dLRlTd9TQnKlq+P1bengPlrGUqMjwOm849Qy5d28=
- In-reply-to: <170625161545.ZM29138@torch.brasslantern.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: <CACcHa=NNdnCAb8YcQkLqnXbQXt5-ttM5=MM=b5kdmUVcWhiuQQ@mail.gmail.com> <1710201498412064@web35j.yandex.ru> <170625161545.ZM29138@torch.brasslantern.com>
26.06.2017, 02:17, "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>:
> Hmm, I never received Nikolay's message, though I see it on the zsh
> archive site.
I am periodically receiving messages that state that some of the messages sent by list to me bounced. Maybe this problem has the same origin.
>
> On Jun 25, 8:34pm, Nikolay Aleksandrovich Pavlov (ZyX) wrote:
> }
> } 25.06.2017, 15:46, "Alexander Gross" <agross@xxxxxxxxxxxxxxxx>:
> } > Hi all,
> } >
> } > I would like to parse some output from a command that generates an array of
> } > the following elements:
> } >
> } > Main System.Xml.XPath - 4.3
> } > Main System.Xml.XPath.XDocument - 4.3
> } > Test Castle.Core - 4.0
> } > Test FsCheck - 2.9
> } >
> } > print -l ${${(s. .)foo}[2]}
>
> The only parameter substitution operator that iterates over elements of
> an array in the way you want is the ${NAME/PATTERN/REPL} syntax. If
> you setopt extendedglob and use (#m) in the pattern, $MATCH will give
> you each of the elements as a string, so you next need to interpret
> each string as words. The (w) subscript modifier does that.
>
> Thus:
>
> setopt extendedglob
> print -lr -- ${foo/(#m)*/${MATCH[(w)2]}}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author