From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7837 invoked from network); 21 Jan 2022 07:49:13 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 Jan 2022 07:49:13 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1642751353; b=klYcPSx9TwXfUasAEL0GWdQos4hMZJ9eFvkp8y18kOC3y8FbmmamOWfePy31xskh4uzl5vc7U0 jHT5/ajNXEHGS01xPRcSPFJ9gljhR0/pzcIB3o/8NObK9gwEaj/piKidBAmYmd3nFnmVbgUsit tEs5htKygKS4SARDQnAwANpkZM+q6SNFGIllt8AtviW233r4TSRIEAg9WEc236NAyo9gQRHBSx KUWLAVQp4LGPfnQyoQ1KBbugVGJY3Xf89B4ofT+GN8Y4vBzpkGGUtw01kUctFk62AAPbnO7RWv XcAICmk7TTCPzX1CRVuJ4DCh4pl/yTpR9Koyv13U/K5yLg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out2-smtp.messagingengine.com) smtp.remote-ip=66.111.4.26; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1642751353; bh=uq1WamjJSpFooVUqqot5fRm0zK9xrqJyVrPv/LtM/yo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=fk1zaZBjrWNRwJctIL/IwskzIXha4obSMgId0hvcX/q2FVtZsBsLI3R0TbwRI0lYizCVKdsWcj XEruqGYwBbUCHIBwwD0YdE0adw/jCZ0rtJRWt6LvhV4Hd2uh9wFntCWZU004oHSl5JyhaM7+Ro J69N5KQ5M4sEKSND7ilF3l9BpXwfQHQeai1/zcTd6NBkNWll30085G9su79MCcslbyX0s1ecO9 R7ZVuDt/5QTWAitvuQvtFlZGDwqS+gaCZ0GWN9Dw0URcaJjAAMdOXt/lLF7fKcwGgRb9ciYQ64 xde5WNJFFxN+yv+ZFdvCkw9Y+hZubA1XSd679ZBJz3+I3Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=g0fWkeqS4vCAby9Ialq2y4oMA8uAYeNJIgG+Pltko3E=; b=ZE6sxYyfrBnnAsQQ6AX975Ekf2 so4gvsIH7iPvNrLOEi0CVQjoFvucmqekcYECXtSUUYoshhDFj8JJVxmWlYtC/YNRMrwnUaLh5wp2a gGfTtA3kSEIKoGomsBRzZZ7UbzyYUYJeA2MagwNS0MjkuPigMk6P5MfYHa3wXFx4KpIRZ5GnCBVov RAsu3e06r9KoU8OJtUlPm/m09RFXFQvCGD+SctaWpZ0WR2RLSISgun93uAYs2ZVy6nBKG27pjMR2T sR6YhQZwkQb/VzZ2l/fNLQWzMlhuuWRHicBP9iT1giuxk+F6Kt8p0NjmcdaTjV90DzU2j9UyjZgm4 ME1tEHFw==; Received: from authenticated user by zero.zsh.org with local id 1nAofZ-000BQj-Fm; Fri, 21 Jan 2022 07:49:13 +0000 Authentication-Results: zsh.org; iprev=pass (out2-smtp.messagingengine.com) smtp.remote-ip=66.111.4.26; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out2-smtp.messagingengine.com ([66.111.4.26]:57199) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1nAoee-000AjZ-JH; Fri, 21 Jan 2022 07:48:17 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id D70555C01EC; Fri, 21 Jan 2022 02:48:15 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 21 Jan 2022 02:48:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm2; bh=g0fWkeqS4vCAby9Ialq2y4oMA8uAYeNJIgG+Pl tko3E=; b=N7CjayR43O5nmY9Gf1hFMUN4ItM4IRtMT+EGKkkOl1AHyZyk9zy2LT F1nIYreYGmfuOuNh6DQWPLaqeMdl3mGIzix3BPLs341cE91WdMHsm74wzsQUhHrI fSB8bE8SI+GPLcdipg6PsdQo1B2H/9olEVrd4vB6Y+KvxNMeShR6+dpqj/VpM+Z7 Lf/44HRN8eN3R2cYst9xugNDotkwzcNbypczGKNJkLzIuc3E+ZN5beY34JE5+IR3 sSv4ygcUFsqCtL0OhCzxfr0awb/YSWxtrlqRf0X7X1u0icjoa/n62Qy+ySfzDc51 ftPEPqzgk5vUjE3YG+NgzMtDnloYQ1Hg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=g0fWkeqS4vCAby9Ialq2y4oMA8uAYeNJIgG+Pltko 3E=; b=UihKpnJ0vsDunZQYdI8w8Y22gByqHSirRUAwAcyEUo4rGgy4Awi8eNGOV 6NR6eZm0XHZYDYOVLYomvAYra3JKtbtAxclpWZGrSSNN0tAOIJw42fth7pAw4yi4 qDDsscmJrQQMeKU9C4gMxqsHBszQElEL/mfq6Gw81Wom8sEp3FCcdt8LnTxoq29P MIw+xsKCfp3IjKpUJS5ZlYRe+YvHKrgtKvodR6IUepuTnB2phUxCFoVqL+01OBMs F6pqzfcGmOi3ALrYf16Vofm36wUy8OteZGpi+uAyjx8N5WaAEsg6f2rLA5hGzhmE cAuDFwc59pk+BvYJSNMvPzUsgDrAQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudelgdduuddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtugfgjggfsehtkedttddtredunecuhfhrohhmpeffrghn ihgvlhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqe enucggtffrrghtthgvrhhnpefgleehtdffuefhgeeuleefffejgedttdelhedvvdeuiefh vefgvdfghfevvdekteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 21 Jan 2022 02:48:15 -0500 (EST) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1005) id 4JgBLz5fs4z3RT; Fri, 21 Jan 2022 07:48:11 +0000 (UTC) Date: Fri, 21 Jan 2022 07:48:11 +0000 From: Daniel Shahaf To: Zsh-Users List Cc: zzapper Subject: Re: zsh-ify a bash script Message-ID: <20220121074811.GA22276@tarpaulin.shahaf.local2> References: <2e3d8557-9f6f-5d17-7517-7f9fcf7be1ce@rayninfo.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 27484 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Andreas Kusalananda Kähäri wrote on Thu, Jan 20, 2022 at 12:26:06 +0100: > On Thu, Jan 20, 2022 at 11:40:56AM +0100, Mikael Magnusson wrote: > > On 1/20/22, Mikael Magnusson wrote: > > > On 1/20/22, Bart Schaefer wrote: > > >> On Wed, Jan 19, 2022 at 12:57 PM zzapper wrote: > > >>> > > >>> Dumb CLI trick. Wanted to find files containing all of several terms > > >>> (dup2, pledge, socketpair, fork), but they could occur anywhere in the > > >>> file: > > >> > > >> Not zsh any more than the first example, but instead of "grep -l" on > > >> the entire file contents for each term ... > > >> > > >> # start by getting the actual occurrences of all the terms: > > >> find . -name '*.c' | xargs egrep > > >> '\<(dup2|pledge|fork|socketpair.*SOCK_STREAM)\>' /dev/null | > > >> # reduce the results to just file names and search terms: > > >> sed -E 's/(^[^:]*\.c:).*\<(dup2|pledge|fork|socketpair)\>.*/\1\2/' | > > >> # make every search term unique per file: > > >> sort -u | > > >> # discard the search terms, leaving only file names: > > >> cut -d : -f 1 | > > >> # count the number of times each file name appears: > > >> uniq -c | > > >> # print names with a count of 4 (the number of search terms): > > >> sed -nE 's/^ *4 //p' > > >> > > >> Adjusting this for edge cases where two search terms appear on the > > >> same line is left as an exercise. > > > > > > This part would probably be fixed by passing -o to grep (didn't test > > > in the above but): > > > % echo foobar|grep -E '(foo|bar)' > > > foobar > > > % echo foobar|grep -oE '(foo|bar)' > > > foo > > > bar > > > > I guess this is more or less the same solution, > > % grep -Eo '(zsfree|zerr|subst)' Src/**/*.c|sort -u|sed 's/:[^:]*'//|uniq -c|grep -E '^\s+3' > > 3 Src/Zle/zle_main.c > > 3 Src/builtin.c > > 3 Src/exec.c > > 3 Src/glob.c > > 3 Src/hist.c > > 3 Src/jobs.c > > 3 Src/signals.c > > 3 Src/subst.c > > 3 Src/utils.c > > > > > > Awk-ifying the end of that pipeline... and just playing around with the > grep a bit for fun (changed to use BREs, but still non-standard due to > -w and -o). > > grep -Fwo -e zsfree -e zerr -e subst -- Src/**/*.c | > awk -F: '!seen[$0]++ && ++count[$1] == 3 { print $1 }' > > This obviously assumes that no pathname contains colons or embedded > newlines. Using glob qualifiers: % has() { <$REPLY grep -q -- "$1" } % print -raC1 -- **/*.c(e*has zerr*e*has zsfree*e*has subst*) Src/Zle/zle_main.c Src/builtin.c Src/exec.c Src/glob.c Src/hist.c Src/jobs.c Src/signals.c Src/subst.c Src/utils.c %