zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zzapper <zsh@rayninfo.co.uk>
Cc: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: zsh-ify a bash script
Date: Wed, 19 Jan 2022 20:12:29 -0800	[thread overview]
Message-ID: <CAH+w=7bEVVC9pFB3dnWXFJnAvmhHTokFoMWB_oCuc+6u=HpvKw@mail.gmail.com> (raw)
In-Reply-To: <2e3d8557-9f6f-5d17-7517-7f9fcf7be1ce@rayninfo.co.uk>

On Wed, Jan 19, 2022 at 12:57 PM zzapper <zsh@rayninfo.co.uk> 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.


  reply	other threads:[~2022-01-20  4:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-19 20:56 zzapper
2022-01-20  4:12 ` Bart Schaefer [this message]
2022-01-20 10:31   ` Mikael Magnusson
2022-01-20 10:40     ` Mikael Magnusson
2022-01-20 11:26       ` Andreas Kusalananda Kähäri
2022-01-20 18:31         ` Bart Schaefer
2022-01-20 22:13           ` Andreas Kusalananda Kähäri
2022-01-21  7:48         ` Daniel Shahaf
2022-01-21  8:50           ` zzapper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bEVVC9pFB3dnWXFJnAvmhHTokFoMWB_oCuc+6u=HpvKw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    --cc=zsh@rayninfo.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).