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 484 invoked from network); 20 Jan 2022 04:13:25 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Jan 2022 04:13:25 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1642652005; b=si7evW3vaxdwtjkzpAEA1Ikrh+WPLhgMfQhdxZrp1b1p7j2/qwNlL1IrDA6kTXd75XqpeUQ17A hTflgu4LJ759yiRbiWWNbuCv92KN/6hWW/gTxyNuGwJPsw5P9iAeCSwG+pA8IPQEhHHfPLAexr aWfLP3p40XZBhoB77xv5Q1SZvPKMQqNQ+FpTf9pG3Mu4AJL7YNkEwbkXzADhwRouwQtYXNDHYk NNqZmz/mMNYb59Jq7c9Sh+Tmqa6KP14pr4CyZWtivzDZarK8i7iH5VPTe7TjHzR+T7vW/OCiUU dQ7hSicgdfplHoz1IseNx9koYOElvNmdFzqvsxxnVEjD8Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f179.google.com) smtp.remote-ip=209.85.219.179; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1642652005; bh=yR6rUabDh6NTLqeVThyDxATBCZAtnQm4DLu7INLUt7c=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=DPJ6/kmKqWZZSuE2p8cB7/3GvQrkZHLheJAsI53Ghzjy8KnDN+VleXVV4WS5VEY4Wl1d2TNSrC +9XXIHiqTRd8JMSubbf+QeuzQD2BgOZr4NFLUxSMYfmnARv9TzlwCIsTNjyW66D0Ap1AcEI8ym 7MaW2zmzxJFqrY2g8+pZmgPDKRfsnmYlHUnZLR/HQ87EmrRuN80u4zKS5WlVJLHH5zuWHrtKBX RZWyd5iPy2mDA/qKG4niyhbc4bDYHeUPEqS+dWUyc0XBDEYDrb/gw64c880XHnbo8XnKSEjyle dRnaqoa3N5UvWQouv0tokGGugqj3yRI4K+N4HHnvy/Nydg==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=MWH8XO51qU1IVSCPEi1zhJMUqZf732DmVztZ2yMM368=; b=SkjaTMr7aSG5wRyZpc4GiH2zgk g+RG/0bNXfJDlPa4+TZO6YsCCdlnBxZK1+adA5MpvTfqpkjIj2QW/Njk/xE7MMw/RtTrmbCcslBFw dFtbdNV/uIQJlZkR2bdh8il+G6ukq0rro5wV8mgqFA3jyZxSHYd4S9DtoI4W0lUnHiWRfsNN7kIge R6FsugOd7LVmw0z1Elc5gsCPqVFKzTLYtmXf8UvOi9tYCeTwVNcJe3cA0hLykyycCDOwj0oxBh/nh Ceft8yL94M7ls/y92yBxzJsTESGlt9zL47XCezHO2rlOHSsCRhi73kzRPovkrtzwHn99C+kR+iCy0 QzsFnaLQ==; Received: from authenticated user by zero.zsh.org with local id 1nAOp9-000Gio-0I; Thu, 20 Jan 2022 04:13:23 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f179.google.com) smtp.remote-ip=209.85.219.179; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-yb1-f179.google.com ([209.85.219.179]:33454) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1nAOoX-000G1i-Pb; Thu, 20 Jan 2022 04:12:46 +0000 Received: by mail-yb1-f179.google.com with SMTP id l68so13473709ybl.0 for ; Wed, 19 Jan 2022 20:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MWH8XO51qU1IVSCPEi1zhJMUqZf732DmVztZ2yMM368=; b=EWX7L5QkrlFxvvli5AyOtE5q5sjxYngTeStK8IiKmRk2FTbezYs3EBvC2G6/tp98LV tSYJ+lzeM6P2Ap49LuoFYmIzyCOI9Re4oUIqR1e2bjZTqLbabeDxCsVXbog9Nn5llrNy t8PBmqMVANAgs128JZ6L8XbqDznoxOAyl8VzmfJ+EHV4nh7lgyvMwBPPh5zEofTPsK4d nNAfYg+Ok9MK5V11AYGwdKV5b52wM5t4td+Ydm+wNJlXt5VVHjs/FJu27qsoxCXVgLNv XJEmcUGareGtBEOenpSHHAZMPqFA3YBTCqfoyPsOGmVuO1Ps4gk609HGKHqwRdkbohxd bOEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MWH8XO51qU1IVSCPEi1zhJMUqZf732DmVztZ2yMM368=; b=mKqmnPCxn5yS3buj/OGKM+KDGy82HEw+rZp7NG6uNh/AcGCRgOlObxSi06MFfRIv7z EyUoLvkYdusT9ImkW/a6xVuuSxs1mRjfKZJJaAm7Nw2wIvNJ07YL+NNXGD4WtrWquKND DVbMxfJLo4EaG9pmowpyl2Fs2m5o+VEM9khAJkI971K2OvjSsFe0VLAKMBgA34eu1cr4 dWEudlaCAxO4ynccJBuPDaYzj0NaB7TjLTAyDGsYLPV7HvW3EZ/OcbGPMiv/FPm+VOez zPvpYQYqj0Z0kcEBD93f6yuwg4bhh/amPRX8HvZWXSUUEMzdmcrRIoHPbR1qrzmcPWrb ZxTQ== X-Gm-Message-State: AOAM5321y3+O6AfgABE2AUI+vXwJd83bLa0BwmPKOX74NZW/Ct4wlIeV WdRntaTzXTD2ysxe7ypJjGQkPtOq9V9Mq5csRoTDmg== X-Google-Smtp-Source: ABdhPJwR6Ijct5KUqjm0GffabXSRfLIQk/40h7s1sHx1jRkJ5h8PKykuVG5d/Yd8xAce9SZfrfR5uXlWEXp2Qvn2+ik= X-Received: by 2002:a25:6b52:: with SMTP id o18mr40216764ybm.590.1642651963330; Wed, 19 Jan 2022 20:12:43 -0800 (PST) MIME-Version: 1.0 References: <2e3d8557-9f6f-5d17-7517-7f9fcf7be1ce@rayninfo.co.uk> In-Reply-To: <2e3d8557-9f6f-5d17-7517-7f9fcf7be1ce@rayninfo.co.uk> From: Bart Schaefer Date: Wed, 19 Jan 2022 20:12:29 -0800 Message-ID: Subject: Re: zsh-ify a bash script To: zzapper Cc: Zsh-Users List Content-Type: text/plain; charset="UTF-8" X-Seq: 27478 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 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. If you have file names with colons in them, the first set of parens in the first sed will need a more precise RE.