From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19857 invoked by alias); 25 Apr 2016 19:49:12 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21492 Received: (qmail 4650 invoked from network); 25 Apr 2016 19:49:11 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=Hs6u0izZq9BKlykPOCjEs73nWon/Cvf/o9piYGGhNE8=; b=kUoWYobzz6Kvm8/EmA5LUTcVVyshRXXYpC6h6IOvn8u4E3hQNpv21eG6sNvp74T+eT OPgKpRdl3xL6/Q0Lgu5sLxxZsGKd/S0XCKHRfP90VKKGXsKvJoQCBQPMGKM0WKl9aZrg uzQXT6eKeGQn9FJ4i7cvV+PpoyxOoa7IV7MY3/P5lGszRImsyfX3j63t4ZJxe1jP0vi2 /azIICMSr8P9VYhq0RCD0C6/QDK70GdPjNZWif2joBfdwC+Ar1l/d20vFWUzrvQSO0A3 tiUVqpCGUgtDt96v1JulhiWB+bB0RpOXXB3xSaAKX5yr/FnAtmhV9QDgVBNZocFjj6GF FohA== X-Gm-Message-State: AOPr4FVXOzbua/dnc5BbgHvzyal6h9R1im5zlyFDOFHNTtuFfmDvFhN6GbczlBkI4QV1Jw== X-Received: by 10.98.75.10 with SMTP id y10mr51031180pfa.32.1461613749469; Mon, 25 Apr 2016 12:49:09 -0700 (PDT) From: Bart Schaefer Message-Id: <160425124932.ZM7571@torch.brasslantern.com> Date: Mon, 25 Apr 2016 12:49:32 -0700 In-Reply-To: Comments: In reply to Sebastian Gniazdowski "Most frequent history words" (Apr 25, 12:36pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: Most frequent history words MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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.