On 3/26/25 3:17 PM, Jerry James wrote:
On Wed, Mar 26, 2025 at 3:01 PM home user via users
<users@lists.fedoraproject.org> wrote:
Good afternoon,

I'm trying to search a directory sub-tree for a specific string.  I use this:

find . -type f -print | xargs grep -l [string] /dev/null

(but without the brackets).  This often works.  But it sometimes fails when the search 
string contains "printable" characters other than letters and digits.  Examples 
of both:

bash.32[.Organ]: find . -type f -print | xargs grep -l D-_qS_3KXBA /dev/null
./organ_dir.txt
bash.33[.Organ]: find . -type f -print | xargs grep -l -ob9LHPEaKY /dev/null
grep: conflicting matchers specified
bash.34[.Organ]: find . -type f -print | xargs grep -l "-ob9LHPEaKY" /dev/null
grep: conflicting matchers specified
bash.35[.Organ]:
bash.35[.Organ]:
bash.35[.Organ]:

bash.36[.Organ]: find . -type f -print | xargs grep -l '-ob9LHPEaKY' /dev/null
grep: conflicting matchers specified
bash.37[.Organ]:

How do I get this to work even when the search string includes (especially 
starts with) printable characters other than digits and letters?

The problem is that those strings start with a '-', so grep thinks you
are specifying more option.  Add -e before your search string:

find . -type f -print | xargs grep -l -e -ob9LHPEaKY [dir]

Also, you're working kind of hard here.  You might find grep's
recursive search option a little easier to use:

grep -rle -ob9LHPEaKY [dir]

Thank-you, Jerry.  That works.
A co-worker back in the late 1980's gave that "find" line.  I'm curious: did 
"grep" have the -r option back then?

Part 2
The sub-tree I'm searching is loaded with huge binary files along with some ".txt" files. 
 The searches take several minutes each.  How do I restrict the search to ".txt" files? 
...
-----
bash.43[ShiPin]: grep -rle -ob9LHPEaKY *.txt
bash.44[ShiPin]: man grep
bash.45[ShiPin]: grep -rle -ob9LHPEaKY *\.txt
bash.46[ShiPin]:
-----
The above should result in one hit.  The man page is confusing me on this.

--
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to