[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: All true assertions in a bash find one liner? ...



On Thu, Feb 27, 2020 at 04:46:08PM +0100, Albretch Mueller wrote:
> > We can't really "see what you mean" until you show us.  Why don't you
> > just tell us the actual problem?  It can't be THAT embarrassing.
> 
>  OK, here it is again. You will see that as part of the output you
> will see a bunch of paths (with the actual matches) that someone were
> not picked by the -printf statement.
> 
> # extensions
> _X=".\(java\|txt\)"
> 
> # search directory
> _SDIR="/home/$(whoami)/java"
> 
> # search string
> _W="java.io.UnsupportedEncodingException;"
> 
> ###
> _DT=$(date +%Y%m%d%H%M%S)
> 
> _LOG_FL=$(basename "${_SDIR}")"_find_${_DT}.log"
> echo "// __ \$_LOG_FL: |${_LOG_FL}|"
> 
> find "${_SDIR}" -type f -iregex .*"${_X}" -printf '"%TD
> %TT",%Ts,%s,"%P"\n' -exec grep --files-with-matches "${_W}" {} \; >
> "${_LOG_FL}" 2>&1
> 
> cat "${_LOG_FL}" | grep -e "^${_SDIR}"

What part of "tell us the actual problem" did you not understand?

Oh, wait.  I already know the answer to that one: all of it. :(

Do you want to search for all files in ~/java whose names end with
.java or .txt and which contain the string
"java.io.UnsupportedEncodingException;" ?

Why is it so hard to write three lines of text that explain what you
are trying to do?  Why do you think that dozens of lines of cryptic
shell code are a valid substitute for that?

Anyway, here's one answer to what I *think* you are trying to achieve:

find ~/java -type f \( -iname '*.java' -o -iname '*.txt' \) \
  -exec grep -l -F 'java.io.UnsupportedEncodingException;' {} +

That is the entire command.  Slap a #!/bin/sh above it and it is the
entire script.

At this point, decades of experience tell me that you will change
the question.  "No, that isn't what I wanted at all!  Isn't it OBVIOUS
from my non-working obfuscated shell code?!"

I try and try and try to avoid that part, by asking you to tell us
the goal up front, in simple English, but I just can't seem to make
that happen.


Reply to: