Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Most frequent history words
- X-seq: zsh-users 21492
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Most frequent history words
- Date: Mon, 25 Apr 2016 12:49:32 -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=Hs6u0izZq9BKlykPOCjEs73nWon/Cvf/o9piYGGhNE8=; b=nspgr4DcueGgUStHjRBQoYCx92xCEUcR+tguAwy6AJXcv6MjRULtj+/6i0vM1dqOve wGq4/G1b5yVRtVrI4q/dnmLuy3eAg9/3TezjFEmRS9QqTcRUDKuOK5GzqAH3RIsCS6Yv KOKtWX1NQRlUhD9ZjBa+ZRifusZc/ITHBpydq3RouatIdC77Oso7x2Lfw91cLlqkx0+7 NaMf94M1+FlBhJt8MiV7twDPYlVL6dNLd5uywZTkDI6WlVdPm2qP1buA2Nf6dU/kaG8l qm489WXrBGZKdRwZ5RY38m62GsKfqskdF+qydao4SGbbi5/Gwhxw0t6QDyssVPSpS48b m+uw==
- In-reply-to: <CAKc7PVCmE-pnDQNCJWS91id7=L+x4M8+q5oLd076AcVgOYHf7A@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: <CAKc7PVCmE-pnDQNCJWS91id7=L+x4M8+q5oLd076AcVgOYHf7A@mail.gmail.com>
On Apr 25, 12:36pm, Sebastian Gniazdowski wrote:
} Subject: Most frequent history words
}
} Hello,
} can the following be made less coreutils dependent, i.e. more pure-Zsh code?
}
} print -rl "${historywords[@]}" | sort | uniq -c | sort -k1,1nr -k2,2 | head
It can, but it's probably not very efficient.
The pipe to sort can be replaced with
print -rl -- ${(o)historywords[@]}
The "uniq -c" would have to be replaced by a loop building a hash whose
keys are words and whose values are the count thereof (making the initial
sort irrelevant).
typeset -A uniq
for k in ${historywords[@]}
do uniq[$k]=$(( ${uniq[$k]:-0} + 1 ))
done
Some quoting on $k such as ${(b)k} is probably required there, this is
the shakiest part of the process.
Then the final "sort -k..." would have to be done by iterating over the
hash, with "head" just taking an array slice.
vk=()
for k v in ${(kv)uniq}
do vk+="$v=$k"
done
print -rl -- ${${${(on)vk}#<->=}[1,10]}
Plus unwrapping there whatever quoting on $k you did in the first loop.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author