Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Array parameter expansion: take n-th word from array elements
- X-seq: zsh-users 22749
- From: Alexander Groß <agross@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Array parameter expansion: take n-th word from array elements
- Date: Sun, 25 Jun 2017 14:44:17 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=therightstuff.de; s=google; h=mime-version:from:date:message-id:subject:to; bh=IZht51imr9eNI7fPHjBUTzLeEc6IpuHYB6rFKrhQm7I=; b=ejVYd8a2euR8xZnBTSMYGLLwRiZEWXmHFXwJur7PNrzUfl/YwGk5fmngO2bxu6NfDt OwoCV+ZoxFWcScL7zdEDd/EoQxslkZlKmfjbXwWNCPHwmzS7Rm99CF+iIyq5LmeI3ayM z0mTOuEakMhP2NV5JB2S0KUoOhbK7YbYykd3w=
- 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
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
E.g.
foo=('a interesting - b' 'a also-interesting - c')
I would like to take the second word from each and every of the array
elements (interesting also-interesting). Unfortunately,
print -l ${foo[2]}
prints the second element, 'a also-interesting - c'.
A for loop works:
local -a filtered
for package in $foo; do
# Split by space and take second word.
filtered+="${${(s. .)package}[2]}"
done
But I wonder if there is a better way using parameter expansion. Here's
what I came up with so far:
print -l ${${(s. .)foo}[2]}
Unfortunately, it just prints 'interesting'.
Any ideas pointing me in the right direction are greatly appreciated!
Alex
--
Alexander Groß
http://therightstuff.de/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author