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 19699 invoked from network); 20 Jan 2022 11:26:59 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Jan 2022 11:26:59 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1642678019; b=IpfzT1tVu9S27CpL75l2ttp6lkDiKDnHnDFdX8P1T7EyNTq39bD+QM+ohz7OTjI7EY2d3PpIpn AOJB+j0bKXo2uLFxW7exVQ1NvDxrUHtz7owZYuzs7gkB4k8v4wXk03Cj9/7bDT43x57pMhjlcp qDkrXSh6aa0smi14KH5sDIz77s3g0VBZaeyQzvpcmzJdzOQAI2Asqg3SKV1Px9njlRqwXEfPE+ rylOZOJRmTE6043EX1cYlWXbLDabzAeb793ORWraYuDI27VPLNbdkLV7fmFppQFOvACss7IRPR D1r5XcFqbjXCLyZx0Shug/URn6cX3LIb42w0f5rb7hhEzQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (hekla.abc.se) smtp.remote-ip=158.174.61.227; dmarc=none header.from=abc.se; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1642678019; bh=4nEjopFZ7Zz2rjNpqSYzN2JjBcjSvvf5sLo5f/3q1og=; 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; b=ZWRRMYdFlqIgtaeJuPQU0Ugbzz5i1uH7TDGzCgwtNVHRqxhla4Tglk+53/XYmFdwrGHdkvVgXa O9BPULJ+8mU7VAlhTkvJWF975Bo34LOO9zzkKa/BiNcxbpYmrmbGGaI6/pADTLf6WFPnzptHhh w2D8NN5iNOodS00AVAmSyTlDcd315DKG2OQL1Tj7nEoqUiILhYHCPeE+99k58KzcyCR8wmbmuE WQYKo0nB2rWgOQ2KA94XIl4ffVm6PWQfGKU4DO4QHnTj0zIRM4WC3SJyTOfEFVUjKqld6VylAK 96VvY7W9UmxlU7CLxbe9llrpopp9H3M2A5oCKpx9EImyZw==; 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=6sV+18HSVhZjxhXIidvwDAgQFFCuZ4YSQ4tjw9nAcnY=; b=AxHNgVspXLXEYgw0RCSetGqcVF XXjME7DAEKS6zi9vSNOHNISbADeXfMz7cjoiEEFg3KQinRnWHLkVmmswwkVbMgR4z+qvgHSPHJAu6 IYTl4ZOozzkraIdVGAp4za+KGkY8C0QKvUALYNxh3mgm4w0wNR0GlYEd6jUCo0KDhgroBJpY/7IKO bpNCQdDXlUDAAgOXspXS/ZN97Nh6OiCVdQ3OfLomZjQaxRB7p04Uup1yJSc8yT2dZo1qSLW67Nu3H LXX3A/lBUTWW/lJ81FCXgOErVI4z6tSN4OHKTrVM7rMKcp74cnJI7/1MC3IvPNew70HZwzHODjI9Z NJ1bb2aQ==; Received: from authenticated user by zero.zsh.org with local id 1nAVal-0005cB-Kq; Thu, 20 Jan 2022 11:26:59 +0000 Authentication-Results: zsh.org; iprev=pass (hekla.abc.se) smtp.remote-ip=158.174.61.227; dmarc=none header.from=abc.se; arc=none Received: from hekla.abc.se ([158.174.61.227]:41450) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1nAVZw-0004tl-5J; Thu, 20 Jan 2022 11:26:09 +0000 Received: from localhost (31-208-84-175.cust.bredband2.com [31.208.84.175]) by hekla.abc.se (OpenSMTPD) with ESMTPSA id ea437acb (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Thu, 20 Jan 2022 12:26:07 +0100 (CET) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 91bcaaeb; Thu, 20 Jan 2022 12:26:06 +0100 (CET) Date: Thu, 20 Jan 2022 12:26:06 +0100 From: Andreas Kusalananda =?utf-8?B?S8OkaMOkcmk=?= To: Mikael Magnusson Cc: Bart Schaefer , zzapper , Zsh-Users List Subject: Re: zsh-ify a bash script Message-ID: Mail-Followup-To: Mikael Magnusson , Bart Schaefer , zzapper , Zsh-Users List References: <2e3d8557-9f6f-5d17-7517-7f9fcf7be1ce@rayninfo.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Seq: 27481 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: 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 > > > -- > Mikael Magnusson 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. -- Andreas (Kusalananda) Kähäri SciLifeLab, NBIS, ICM Uppsala University, Sweden .