Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (1 / 5) |
Uptime: | 47:13:46 |
Calls: | 422 |
Files: | 1,024 |
Messages: | 90,388 |
BTW note on egrep deprecation:
On 3/13/2025 7:58 PM, rbowman wrote:
[redacted]
As a variation on that theme:
find . -name "*.c" | xargs grep foobar
Not what you asked for but handy.
For your specific example
grep -r --include='*.c' foobar
As a variation on that theme:
find . -name "*.c" | xargs grep foobar
Not what you asked for but handy.
On Thu, 3/13/2025 2:17 PM, Adam wrote:
The following ...
grep -e pattern1 -e pattern2 wget_output_file.txt
is NOT giving the result that I'm looking for, which is BOTH patterns must be in the file.
"The egrep variant supports an extended regular expression syntax added by Alfred Aho
after Ken Thompson's original regular expression implementation.[12]
The "fgrep" variant searches for any of a list of fixed strings using
the Aho–Corasick string matching algorithm."
*******
sample.txt
----------
I am a cat
I am a dog
I am a cat or a dog
I am an elephant
(stdout)
$ egrep "cat|dog" sample.txt
I am a cat
I am a dog
I am a cat or a dog
"If at first you don't grep, try try again... with a egrep or a fgrep" :-)
It's a good thing these are documented.
Paul
The following ...
grep -e pattern1 -e pattern2 wget_output_file.txt
is NOT giving the result that I'm looking for, which is BOTH patterns must be in the file.
On 03/13/2025 12:16 PM, Paul wrote:
On Thu, 3/13/2025 2:17 PM, Adam wrote:
The following ...
grep -e pattern1 -e pattern2 wget_output_file.txt
is NOT giving the result that I'm looking for, which is BOTH patterns must be in the file.
"The egrep variant supports an extended regular expression syntax added by Alfred Aho
after Ken Thompson's original regular expression implementation.[12]
The "fgrep" variant searches for any of a list of fixed strings using
the Aho–Corasick string matching algorithm."
*******
sample.txt
----------
I am a cat
I am a dog
I am a cat or a dog
I am an elephant
(stdout)
$ egrep "cat|dog" sample.txt
I am a cat
I am a dog
I am a cat or a dog
"If at first you don't grep, try try again... with a egrep or a fgrep" :-) >>
It's a good thing these are documented.
Paul
I'm looking for AND (not OR) operator. So, both patterns must be in the file (not line) or FALSE is returned.
I'm looking for AND (not OR) operator. So, both patterns must be in the
file (not line) or FALSE is returned.
Il Thu, 13 Mar 2025 12:56:42 -0700, Adam ha scritto:
I'm looking for AND (not OR) operator. So, both patterns must be in the
file (not line) or FALSE is returned.
$ ( grep -l pattern1 file | xargs grep -l pattern2 ) || false
You can do it better. Read the manual of the involved commands, if you
like.
On 03/13/2025 12:16 PM, Paul wrote:
On Thu, 3/13/2025 2:17 PM, Adam wrote:
The following ...
grep -e pattern1 -e pattern2 wget_output_file.txt
is NOT giving the result that I'm looking for, which is BOTH
patterns must be in the file.
"The egrep variant supports an extended regular expression syntax
added by Alfred Aho after Ken Thompson's original regular expression
implementation.[12]
The "fgrep" variant searches for any of a list of fixed strings
using the Aho–Corasick string matching algorithm."
*******
sample.txt
----------
I am a cat
I am a dog
I am a cat or a dog
I am an elephant
(stdout)
$ egrep "cat|dog" sample.txt
I am a cat
I am a dog
I am a cat or a dog
"If at first you don't grep, try try again... with a egrep or a fgrep" :-) >>
It's a good thing these are documented.
Paul
I'm looking for AND (not OR) operator. So, both patterns must be in the
file (not line) or FALSE is returned.
On 03/13/2025 01:44 PM, Lem Novantotto wrote:if-it-contains-multiple-patterns-anywhere-in-the
Il Thu, 13 Mar 2025 12:56:42 -0700, Adam ha scritto:Thanks, your post led me to...
I'm looking for AND (not OR) operator. So, both patterns must be in
the file (not line) or FALSE is returned.
$ ( grep -l pattern1 file | xargs grep -l pattern2 ) || false
You can do it better. Read the manual of the involved commands, if you
like.
How can I search a file to see if it contains multiple patterns anywhere
in the file? https://askubuntu.com/questions/1501703/how-can-i-search-a-file-to-see-
======================================================================== waltinator's answer...
It can be done using multiple grep commands. Read man grep xargs, and do something like
grep -l 'pattern1' -f filelist | \
xargs grep -l 'pattern2` | \
xargs grep -l 'pattern3'
The first grep produces a list of files containing the first pattern.
The second (xargs grep) searches for the second pattern in the files containing the first pattern. ========================================================================
On Thu, 13 Mar 2025 14:38:45 -0700, Adam wrote:
On 03/13/2025 01:44 PM, Lem Novantotto wrote:if-it-contains-multiple-patterns-anywhere-in-the
Il Thu, 13 Mar 2025 12:56:42 -0700, Adam ha scritto:Thanks, your post led me to...
I'm looking for AND (not OR) operator. So, both patterns must be in
the file (not line) or FALSE is returned.
$ ( grep -l pattern1 file | xargs grep -l pattern2 ) || false
You can do it better. Read the manual of the involved commands, if you
like.
How can I search a file to see if it contains multiple patterns anywhere
in the file?
https://askubuntu.com/questions/1501703/how-can-i-search-a-file-to-see-
========================================================================
waltinator's answer...
It can be done using multiple grep commands. Read man grep xargs, and do
something like
grep -l 'pattern1' -f filelist | \
xargs grep -l 'pattern2` | \
xargs grep -l 'pattern3'
The first grep produces a list of files containing the first pattern.
The second (xargs grep) searches for the second pattern in the files
containing the first pattern.
========================================================================
As a variation on that theme:
find . -name "*.c" | xargs grep foobar
Not what you asked for but handy.
On 03/13/2025 01:44 PM, Lem Novantotto wrote:
Il Thu, 13 Mar 2025 12:56:42 -0700, Adam ha scritto:
I'm looking for AND (not OR) operator. So, both patterns must be in the
file (not line) or FALSE is returned.
$ ( grep -l pattern1 file | xargs grep -l pattern2 ) || false
You can do it better. Read the manual of the involved commands, if you
like.
Thanks, your post led me to...
How can I search a file to see if it contains multiple patterns anywhere
in the file? https://askubuntu.com/questions/1501703/how-can-i-search-a-file-to-see-if-it-contains-multiple-patterns-anywhere-in-the
======================================================================== waltinator's answer...
It can be done using multiple grep commands. Read man grep xargs, and do something like
grep -l 'pattern1' -f filelist | \
xargs grep -l 'pattern2` | \
xargs grep -l 'pattern3'
The first grep produces a list of files containing the first pattern.
The second (xargs grep) searches for the second pattern in the files containing the first pattern. ========================================================================