Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: can I control brace expansion's "sort"/"display" order?
- X-seq: zsh-users 13175
- From: Eric De Mund <ead@xxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: can I control brace expansion's "sort"/"display" order?
- Date: Sun, 31 Aug 2008 03:17:28 -0700
- Disposition-notification-to: ead@xxxxxxxxx
- In-reply-to: <237967ef0808310241w3b71cf1el9d1c140379660b8@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <18618.26046.529685.352779@xxxxxxxxxxx> <237967ef0808310241w3b71cf1el9d1c140379660b8@xxxxxxxxxxxxxx>
- Reply-to: Eric De Mund <ead@xxxxxxxxx>
Mikael,
Eric De Mund <ead@xxxxxxxxx>:
> Can I control brace expansion's "sort" or "display" order?
>
> For instance this zsh echo results in this output:
>
> % echo {white,black}{bird,fish}{21..24} | tr ' ' '\n'
> # current output order
> whitebird21
> whitebird22
> whitebird23
> whitebird24
> whitefish21
> whitefish22
> whitefish23
> whitefish24
> blackbird21
> blackbird22
> blackbird23
> blackbird24
> blackfish21
> blackfish22
> blackfish23
> blackfish24
> %
>
> But what if instead of this order I wanted the last brace to cycle
> most slowly, followed by the first, followed by the second, like so:
>
> % echo {white,black}{bird,fish}{21..24} | tr ' ' '\n'
> # desired output order
> whitebird21
> whitefish21
> blackbird21
> blackfish21
> whitebird22
> whitefish22 # oops: I had these two swapped in my original email
> blackbird22 # oops: I had these two swapped in my original email
> blackfish22
> whitebird23
> whitefish23
> blackbird23
> blackfish23
> whitebird24
> whitefish24
> blackbird24
> blackfish24
> %
>
> Is there any way to accomplish this?
>
> My problem is that I'm trying to get files added to a zip archive in
> a particular order, and this order is neither brace expansion sort/
> display order nor lexicographical order.
Mikael Magnusson <mikachu@xxxxxxxxx>:
] You can probably do it with some for-looping, like
] setopt shortloops
] % for a in white black; for b in fish bird; for c in {21..24}; echo $a$b$c
] whitefish21
] whitefish22
] whitefish23
] whitefish24
] whitebird21
] whitebird22
] whitebird23
] whitebird24
] blackfish21
] blackfish22
] blackfish23
] blackfish24
] blackbird21
] blackbird22
] blackbird23
] blackbird24
]
] Now you can just swap the order of the loops
] % for b in fish bird; for a in white black; for c in {21..24}; echo $a$b$c
] whitefish21
] whitefish22
] whitefish23
] whitefish24
] blackfish21
] blackfish22
] blackfish23
] blackfish24
] whitebird21
] whitebird22
] whitebird23
] whitebird24
] blackbird21
] blackbird22
] blackbird23
] blackbird24
Thank you very much! This is great. This works for me. I'd use the
following solution, having:
o the first variable represent the slowest cycling field (in my case
the third field),
o the second variable represent the next slowest cycling field (in my
case the first field), and
o the third variable represent the next slowest cycling field (in my
case the second field).
Like so:
% for a in {21..24}; for b in {white,black}; for c in {bird,fish}; \
echo $b$c$a
whitebird21
whitefish21
blackbird21
blackfish21
whitebird22
whitefish22
blackbird22
blackfish22
whitebird23
whitefish23
blackbird23
blackfish23
whitebird24
whitefish24
blackbird24
blackfish24
%
Regards,
Eric
--
Eric De Mund | Ixian Systems | Jab: eadixian@xxxxxxxxxx/main
ead@xxxxxxxxx | 650 Castro St, #120-210 | Y!M: ead0002
ixian.com/ead/ | Mountain View, CA 94041 | ICQ: 811788
Messages sorted by:
Reverse Date,
Date,
Thread,
Author