Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #223765
| From | David Christensen <dpchrist@holgerdanske.com> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: one liner, how do you know which match happened ... |
| Date | 2020-06-20 22:30 +0200 |
| Message-ID | <AjShI-3TC-19@gated-at.bofh.it> (permalink) |
| References | <AjIV3-6Jq-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 2020-06-20 03:20, Albretch Mueller wrote:
> _X=".\(html\|txt\)"
> _SDIR="$(pwd)"
>
> _AR_TERMS=(
> Kant
> "Gilbert Ryle"
> Hegel
> )
>
> for iZ in ${!_AR_TERMS[@]}; do
> find "${_SDIR}" -type f -iregex .*"${_X}" -exec grep -il
> "${_AR_TERMS[$iZ]}" {} \;
> done # iZ: terms search/grep'ped inside text files; echo "~";
>
>
> # this would be much faster
>
> find "${_SDIR}" -type f -iregex .*"${_X}" -exec grep -il
> "Kant\|Gilbert Ryle\|Hegel" {} \;
>
> but how do I know which match happened in order to save it into separate files?
>
> grep doesn't do replacements:
>
> https://stackoverflow.com/questions/16197406/grep-regex-replace-specific-find-in-text-file
>
> but at least (in my way to understand reality, since it must try such
> searches sequentially) it should give you the index of the match and
> if grep doesn't do that I am sure some other batch utility would (I
> havenever used sed in my code)
>
> lbrtchx
It is difficult to infer your intent from code alone. It would help if
you posted a problem statement in plain English.
Are you willing to use a language other than sh(1)? If so, what
language(s)?
David
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
one liner, how do you know which match happened ... Albretch Mueller <lbrtchx@gmail.com> - 2020-06-20 12:30 +0200
Re: one liner, how do you know which match happened ... <tomas@tuxteam.de> - 2020-06-20 13:10 +0200
Re: one liner, how do you know which match happened ... Albretch Mueller <lbrtchx@gmail.com> - 2020-06-24 12:40 +0200
Re: one liner, how do you know which match happened ... tomas@tuxteam.de - 2020-06-24 13:00 +0200
Re: one liner, how do you know which match happened ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-06-24 14:20 +0200
Re: one liner, how do you know which match happened ... Albretch Mueller <lbrtchx@gmail.com> - 2020-06-24 17:30 +0200
Re: one liner, how do you know which match happened ... David Wright <deblis@lionunicorn.co.uk> - 2020-06-20 16:40 +0200
Re: one liner, how do you know which match happened ... David Christensen <dpchrist@holgerdanske.com> - 2020-06-20 22:30 +0200
Re: one liner, how do you know which match happened ... davidson <davidson@freevolt.org> - 2020-06-20 23:10 +0200
Re: one liner, how do you know which match happened ... davidson <davidson@freevolt.org> - 2020-06-20 23:30 +0200
Re: one liner, how do you know which match happened ... Klaus Singvogel <deb-user-ml@singvogel.net> - 2020-06-21 01:10 +0200
Re: one liner, how do you know which match happened ... Greg Wooledge <wooledg@eeg.ccf.org> - 2020-06-22 13:50 +0200
csiph-web