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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14582 invoked from network); 20 Jan 2022 10:41:51 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Jan 2022 10:41:51 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1642675311; b=R2Nuj4uFTm7q6LEp13+xTqKeyltMRQPn3nEa32sCdfioaFCqcq33RyHaLpFb8VzXOCReXVzABF a7Z+jZk4UGJP5EYZwa3dZTL70VmdQkxXZhDfWD5OBWtghHzxnutlvD0aieDkUO1wbAigTVavwn YzwqttsfVa5ZRukJU64sDPlt0RQbudDaV+/di8N5v0Tts3yDuz91W/gV0c8lp1NN6e5aEBQQd0 /uxAa4/S24VFth7+Xc7/pDft7BhhFJKYRG92A/44FpkvzDlfD1wATMJx/qejG/v3xFot53KzM5 tb9ay6M8AzNm9G5fNNSPEBhVHY2TIym4rwbDlIviPg2VmA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ua1-f48.google.com) smtp.remote-ip=209.85.222.48; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1642675311; bh=khSrEI6oN1z8x8s3GXOv+wdkwCNnXzEIJtGiK/O5a1w=; 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:References: In-Reply-To:MIME-Version:DKIM-Signature:DKIM-Signature; b=lTHla6pXREgZ7e1NTZcFOZJd1d6x5xhpWJW4JNam/feXDHjA/mIWh+r4o91tgHq5cosk8l03E3 HCaNHheaL/VL4iuJ+ZvyOPVp1BfDlHbxZWWeXLKh7k2XLxz9gfnASs5nmcU2/UNOo26AurT1dS d+dtsD+Lf2YakXSPNRLe2obeyXRbF+es3HnqwAloC4WV+ZWwrKu7KGMumAVZfvb5U4G0CYMchw zrzQw6gZQoqZP27dhmtDPzvoNDEQsQbc3ZQ7FojOMgVyET/CCUiQYJYlrvAxCeMd1RaJGe9Od8 FtW+dcPnQTDcpTiW8dd0yt0IwfrJhM+tvgxzPWYJKVakNw==; 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:References:In-Reply-To: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=NioK3yiRGf84Fw+WRl8wPaZbaUqT7FIniBTz2IK8bqA=; b=dZYJwnVdlNiT7QCdzDRklb8YMA adwSO4a5jNs625nBSERM46F6r/X2Wp/jnL7ZNJlv8UQbG/B5YXyX2U0Cco1dZ/CdwkKPkyk5sR83f VtyuoCRClxHbwU5+BUZBfGb6n23BRQdvawLUHRVmpJScQcbiD4iHuS022gU4VvKEdBxdfS4li+wOb 4mz+BjCBUcwdJvpxFNsTc9Fy3VJvPaPRqcp9g4oNWDxCejCjgGUcvQfRLyC0YCy5zhmsxbKYzK2q1 mlPpzHGeKxcGeMkbiOig206nG3kiy+WQTRz+5JT9PPlF79ZQsp5O1fMBqJcFzKBRVMkkwcgErp9vs 1oXxBylw==; Received: from authenticated user by zero.zsh.org with local id 1nAUt4-0003Sg-JK; Thu, 20 Jan 2022 10:41:50 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ua1-f48.google.com) smtp.remote-ip=209.85.222.48; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ua1-f48.google.com ([209.85.222.48]:35774) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1nAUsE-0002im-0T; Thu, 20 Jan 2022 10:40:58 +0000 Received: by mail-ua1-f48.google.com with SMTP id m90so10047446uam.2 for ; Thu, 20 Jan 2022 02:40:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=NioK3yiRGf84Fw+WRl8wPaZbaUqT7FIniBTz2IK8bqA=; b=jkuvrcH7+M5kiutNBr/tQ6QUYCxKje7Lq/0O6nWeL51tfNHWHGRnZp8Welb3A1I0L4 oh3TCftGK+gaIxaMfrKjmZBhyNgqSW0mu4lCJGsrBnqPsXjDTGkYeSWeDhamsGEu4eS6 VOl9sCUzwlk7l89RqiTcSv3nfZABiqzDmAY2llX46BTC5fNi6HU896CcFvlTmnEDyBnx vHxWE4TpfZFtYjS/MeASJxZqld4tsMCWLd5CBF95JwC88u/K8aWqQP3XqJsQ82fAyvYx DsbjDusaF8b7TDZFJLmQJJXmCSicwjzqIG2lDkPtlPx7qo5hUsLkMDVfeJBkVV4DYMef edSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=NioK3yiRGf84Fw+WRl8wPaZbaUqT7FIniBTz2IK8bqA=; b=ICfm8GZycWFz9KDVdKrGkKtkkyI+efub6DtF/y2v1H9Oj9AxH0Wj85hdGL3syVQy0C BBkILguJtdd5LvVbZKZ4oimhm4InrAUFNZdM7zYeKJDkcOerYwX/P4aSV5QRornnyNp0 nAtHvfT4R5ThttBlEjGM5dCB9yoGbLmWH3vwTGsNUrhMO2i5S2Fv6HhbPUOd5c5PKW95 etT5bV5+smKpere59KIM/WgsxX6Q7b28iiBRMc+w3aOSmdnU3Ic6JFRR5ZhnmG0LdEuQ Fa9yMqBkseDPMmYMYlRmxh2HRSeBdnzyWiIQ6hfqJj4RYW0JxXbVmLS9zr01KFRwDPQy ILXA== X-Gm-Message-State: AOAM530sHEwfV7bL4LxcmdyUfwa18aEkbB9q4MWzS/pOIEr3yGGaGY7j Dr0imIWfU5l6Bru2S30tkDsjeTfMvhlLHc2GbU8LXpBR X-Google-Smtp-Source: ABdhPJyaKfx+NXlLF0+5Xv9PkWZrGKAgbA8QRssIZqEByMiPuSs2+D0SZYi9zijn3ZGTakVFgTG8tEKXrk0VrM4xPy8= X-Received: by 2002:ab0:3ae:: with SMTP id 43mr5224476uau.43.1642675256922; Thu, 20 Jan 2022 02:40:56 -0800 (PST) MIME-Version: 1.0 Received: by 2002:ab0:2551:0:0:0:0:0 with HTTP; Thu, 20 Jan 2022 02:40:56 -0800 (PST) In-Reply-To: References: <2e3d8557-9f6f-5d17-7517-7f9fcf7be1ce@rayninfo.co.uk> From: Mikael Magnusson Date: Thu, 20 Jan 2022 11:40:56 +0100 Message-ID: Subject: Re: zsh-ify a bash script To: Bart Schaefer Cc: zzapper , Zsh-Users List Content-Type: text/plain; charset="UTF-8" X-Seq: 27480 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 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