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 22751
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: Array parameter expansion: take n-th word from array elements
- Date: Sun, 25 Jun 2017 16:15:45 -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=DORyMiqsYnuvjQ98PKx/4XwBqI0CrC4/waynfKI4QIY=; b=b/NtMHqhnK++0C/XYFCoWetyCOQtwxPfdGRhGdDvdVLffdXqNWE0tE4R2mpidaq7Er GGyPTwCAsF8P9ihaKECaOsJA2AvlWOuYqk0DCdIBk0bl2I2/rEbOgRHvS2JYEMfASJjM A/SfVJOoyz7Dw0f+QkES7gdsZB0JKuQIrtjkORwCLctc77D2HNessH2PvLTabw14ciWz WvBqeZsWN0lB4MKigv545bidSPos5Ky7MfuqV13EIqoCZAfHG12OmsJ5eA+DLobQ+wIi zpRqCqyUbUY1uLibba0RBQiY41Ub9UrwB43CAuMAI/j6AjXYQp8aR0FNycb3XozD7XBw 0hAw==
- In-reply-to: <1710201498412064@web35j.yandex.ru>
- 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>
Hmm, I never received Nikolay's message, though I see it on the zsh
archive site.
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