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

