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?
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]
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.
On Wed, Mar 26, 2025 at 5:19 PM Jerry James loganjerry@gmail.com wrote:
On Wed, Mar 26, 2025 at 3:01 PM home user via users users@lists.fedoraproject.org wrote:
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
[...]
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]
Or if you wish to use find, try "find . -type f -name '*ob9LHPEaKY*'". Note that with the "*" wildcard you need to put the string in single quotes. If you want a case-insensitive match, use -iname instead of -name.
On 3/26/25 2:49 PM, Go Canes wrote:
On Wed, Mar 26, 2025 at 5:19 PM Jerry James loganjerry@gmail.com wrote:
On Wed, Mar 26, 2025 at 3:01 PM home user via users users@lists.fedoraproject.org wrote:
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
[...]
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]
Or if you wish to use find, try "find . -type f -name '*ob9LHPEaKY*'". Note that with the "*" wildcard you need to put the string in single quotes. If you want a case-insensitive match, use -iname instead of -name.
He's searching in the files, not searching for a filename.
On Wed, Mar 26, 2025 at 5:48 PM home user via users users@lists.fedoraproject.org wrote:
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? ...
Same as my previous reply, adding .txt to the wildcard - "find . -type f -name '*ob9LHPEaKY*.txt'"
On Wed, Mar 26, 2025 at 5:52 PM Samuel Sieb samuel@sieb.net wrote:
On 3/26/25 2:49 PM, Go Canes wrote:
On Wed, Mar 26, 2025 at 5:19 PM Jerry James loganjerry@gmail.com wrote:
On Wed, Mar 26, 2025 at 3:01 PM home user via users users@lists.fedoraproject.org wrote:
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
[...]
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]
Or if you wish to use find, try "find . -type f -name '*ob9LHPEaKY*'". Note that with the "*" wildcard you need to put the string in single quotes. If you want a case-insensitive match, use -iname instead of -name.
He's searching in the files, not searching for a filename.
Ah! Missed that - sorry!
So use the recursive grep, or "find . -type f -name '*.txt' -exec grep -l -- ob9LHPEaKY {} ;" to restrict it to just files with a .txt extension.
On 3/26/25 3:52 PM, Samuel Sieb wrote:
On 3/26/25 2:49 PM, Go Canes wrote:
On Wed, Mar 26, 2025 at 5:19 PM Jerry James loganjerry@gmail.com wrote:
On Wed, Mar 26, 2025 at 3:01 PM home user via users users@lists.fedoraproject.org wrote:
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
[...]
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]
Or if you wish to use find, try "find . -type f -name '*ob9LHPEaKY*'". Note that with the "*" wildcard you need to put the string in single quotes. If you want a case-insensitive match, use -iname instead of -name.
He's searching in the files, not searching for a filename.
Thank-you Samuel. The "-I" works. Now I just gotta redefine my aliases in my "~/.bashrc".
SOLVED! Thank-you, everyone.
On Wed, 2025-03-26 at 15:47 -0600, home user via users wrote:
A co-worker back in the late 1980's gave that "find" line. I'm curious: did "grep" have the -r option back then?
Maybe my memory is faulty but I don't remember grep ever not having the '-r' option and I've been using it since the 1970s. In fact xargs hasn't been around forever (though it's pretty old) and is certainly younger than grep.
poc
On 3/26/25 4:14 PM, Patrick O'Callaghan wrote:
On Wed, 2025-03-26 at 15:47 -0600, home user via users wrote:
A co-worker back in the late 1980's gave that "find" line. I'm curious: did "grep" have the -r option back then?
Maybe my memory is faulty but I don't remember grep ever not having the '-r' option and I've been using it since the 1970s. In fact xargs hasn't been around forever (though it's pretty old) and is certainly younger than grep.
poc
ok. Thank-you. Hmmm... Unix really does go that far back. Linux goes back to 1991 according to wikipedia.
On Wed, 2025-03-26 at 17:39 -0600, home user via users wrote:
On 3/26/25 4:14 PM, Patrick O'Callaghan wrote:
On Wed, 2025-03-26 at 15:47 -0600, home user via users wrote:
A co-worker back in the late 1980's gave that "find" line. I'm curious: did "grep" have the -r option back then?
Maybe my memory is faulty but I don't remember grep ever not having the '-r' option and I've been using it since the 1970s. In fact xargs hasn't been around forever (though it's pretty old) and is certainly younger than grep.
poc
ok. Thank-you. Hmmm... Unix really does go that far back. Linux goes back to 1991 according to wikipedia.
I started using UNIX in 1976. That was the "5th Edition", which relatively few people outside Bell Labs ever saw. Not to be confused with the later System V.
poc
On Wed, Mar 26, 2025 at 03:00:21PM -0600, home user via users 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?
Your search strings look like options. For example, -ob9... looks like the -o option, not a search string.
A very common way around this is to use "--" at the end of your options. Many commands recognize the solo double dash to mean no more options follow. So:
find . -type f -print | xargs grep -l -- '-ob9LHPEaKY' /dev/null
should work.
On 3/27/25 10:29 PM, Jon LaBadie wrote:
On Wed, Mar 26, 2025 at 03:00:21PM -0600, home user via users 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?
Your search strings look like options. For example, -ob9... looks like the -o option, not a search string.
A very common way around this is to use "--" at the end of your options. Many commands recognize the solo double dash to mean no more options follow. So:
find . -type f -print | xargs grep -l -- '-ob9LHPEaKY' /dev/null
should work.
Thank-you, Jon. That works, and it also works if I use "grep" directly (no "find").