Hi All,
Without using two lines of grep, is there a way to
do a logical AND or OR with grep?
either abc or xyz
cat xxx | grep -i abc OR xyz
or must have both
cat xxx | grep -i abc AND xyz
Many thanks,
-T
|
|
0
|
|
|
|
Reply
|
Todd
|
5/10/2010 5:44:33 PM |
|
On 05/10/2010 10:44 AM, Todd wrote:
> Hi All,
>
> Without using two lines of grep, is there a way to
> do a logical AND or OR with grep?
>
> either abc or xyz
>
> cat xxx | grep -i abc OR xyz
>
> or must have both
>
> cat xxx | grep -i abc AND xyz
>
> Many thanks,
> -T
I figured out the logical OR.
$ grep -i -E "Nested|vpid" WS08-1.info.txt
Nested Paging: off
VT-x VPID: off
Anyone know how to do a logical AND?
-T
|
|
0
|
|
|
|
Reply
|
Todd
|
5/10/2010 7:32:57 PM
|
|
Todd <todd@invalid.com> writes:
> Without using two lines of grep, is there a way to
> do a logical AND or OR with grep?
You can do logical OR.
> either abc or xyz
>
> cat xxx | grep -i abc OR xyz
cat xxx | grep '\(abc\|xyz\)'
cat xxx | grep -E '(abc|xyz)'
cat xxx | egrep '(abc|xyz)'
> or must have both
>
> cat xxx | grep -i abc AND xyz
Not really.
cat xxx | egrep '(abc.*xyz|xyz.*abc)'
but this obviously doesn't scale...
Vilmos
|
|
0
|
|
|
|
Reply
|
Vilmos
|
5/10/2010 7:35:37 PM
|
|
On 05/10/2010 12:35 PM, Vilmos Soti wrote:
> Todd<todd@invalid.com> writes:
>
>> Without using two lines of grep, is there a way to
>> do a logical AND or OR with grep?
>
> You can do logical OR.
>
>> either abc or xyz
>>
>> cat xxx | grep -i abc OR xyz
>
> cat xxx | grep '\(abc\|xyz\)'
> cat xxx | grep -E '(abc|xyz)'
> cat xxx | egrep '(abc|xyz)'
>
>> or must have both
>>
>> cat xxx | grep -i abc AND xyz
>
> Not really.
>
> cat xxx | egrep '(abc.*xyz|xyz.*abc)'
>
> but this obviously doesn't scale...
>
> Vilmos
Thank you.
Figured out the logical AND, but not with grep:
$ awk '/Nested/ && /Paging/' WS08-1.info.txt
Nested Paging: off
|
|
0
|
|
|
|
Reply
|
Todd
|
5/10/2010 7:43:50 PM
|
|
On Mon, 10 May 2010 12:32:57 -0700, Todd wrote:
> On 05/10/2010 10:44 AM, Todd wrote:
>> Without using two lines of grep, is there a way to
>> do a logical AND or OR with grep?
>>
>> either abc or xyz
>>
>> cat xxx | grep -i abc OR xyz
>>
>> or must have both
>>
>> cat xxx | grep -i abc AND xyz
> Anyone know how to do a logical AND?
cat xxx | grep -i abc | grep -i xyz
Or is that "two lines of grep"?
Bob T.
|
|
0
|
|
|
|
Reply
|
Bob
|
5/10/2010 7:50:37 PM
|
|
Todd wrote:
> On 05/10/2010 12:35 PM, Vilmos Soti wrote:
>> Todd<todd@invalid.com> writes:
>>
>>> Without using two lines of grep, is there a way to
>>> do a logical AND or OR with grep?
>>
>> You can do logical OR.
>>
>>> either abc or xyz
>>>
>>> cat xxx | grep -i abc OR xyz
>>
>> cat xxx | grep '\(abc\|xyz\)'
>> cat xxx | grep -E '(abc|xyz)'
>> cat xxx | egrep '(abc|xyz)'
>>
>>> or must have both
>>>
>>> cat xxx | grep -i abc AND xyz
>>
>> Not really.
>>
>> cat xxx | egrep '(abc.*xyz|xyz.*abc)'
>>
>> but this obviously doesn't scale...
>>
>> Vilmos
>
>
> Thank you.
>
> Figured out the logical AND, but not with grep:
>
> $ awk '/Nested/ && /Paging/' WS08-1.info.txt
> Nested Paging: off
>
:-)
WE always used to reach for the awk manual when grep got silly.
|
|
0
|
|
|
|
Reply
|
The
|
5/10/2010 7:52:30 PM
|
|
On 05/10/2010 12:50 PM, Bob Tennent wrote:
> On Mon, 10 May 2010 12:32:57 -0700, Todd wrote:
> > On 05/10/2010 10:44 AM, Todd wrote:
>
> >> Without using two lines of grep, is there a way to
> >> do a logical AND or OR with grep?
> >>
> >> either abc or xyz
> >>
> >> cat xxx | grep -i abc OR xyz
> >>
> >> or must have both
> >>
> >> cat xxx | grep -i abc AND xyz
>
> > Anyone know how to do a logical AND?
>
> cat xxx | grep -i abc | grep -i xyz
>
> Or is that "two lines of grep"?
>
> Bob T.
I am being a perfectionist and trying to get it
all on one line. :'[
-T
|
|
0
|
|
|
|
Reply
|
Todd
|
5/10/2010 7:56:41 PM
|
|
>> Figured out the logical AND, but not with grep:
>>
>> $ awk '/Nested/ && /Paging/' WS08-1.info.txt
>> Nested Paging: off
>>
> :-)
>
> WE always used to reach for the awk manual when grep got silly.
Do you know how to do it (with awk) case insensitive?
|
|
0
|
|
|
|
Reply
|
Todd
|
5/10/2010 7:57:56 PM
|
|
Todd wrote:
>>> Figured out the logical AND, but not with grep:
>>>
>>> $ awk '/Nested/ && /Paging/' WS08-1.info.txt
>>> Nested Paging: off
>>>
>> :-)
>>
>> WE always used to reach for the awk manual when grep got silly.
>
> Do you know how to do it (with awk) case insensitive?
Sorry.. too many years have passed..and I sold my sed awk and grep
o'reilly :-)
|
|
0
|
|
|
|
Reply
|
The
|
5/10/2010 8:11:12 PM
|
|
The Natural Philosopher wrote:
> Todd wrote:
>> On 05/10/2010 12:35 PM, Vilmos Soti wrote:
>>> Todd<todd@invalid.com> writes:
>>>
>>>> Without using two lines of grep, is there a way to
>>>> do a logical AND or OR with grep?
>>>
>>> You can do logical OR.
>>>
>>>> either abc or xyz
>>>>
>>>> cat xxx | grep -i abc OR xyz
>>>
>>> cat xxx | grep '\(abc\|xyz\)'
>>> cat xxx | grep -E '(abc|xyz)'
>>> cat xxx | egrep '(abc|xyz)'
>>>
>>>> or must have both
>>>>
>>>> cat xxx | grep -i abc AND xyz
>>>
>>> Not really.
>>>
>>> cat xxx | egrep '(abc.*xyz|xyz.*abc)'
>>>
>>> but this obviously doesn't scale...
>>>
>>> Vilmos
>>
>>
>> Thank you.
>>
>> Figured out the logical AND, but not with grep:
>>
>> $ awk '/Nested/ && /Paging/' WS08-1.info.txt
>> Nested Paging: off
>>
> :-)
>
> WE always used to reach for the awk manual when grep got silly.
I hate awk. The commmands are so cryptic that whomever tries to read
the code later has to work at it to understand it. A simple shell
script is more useful and reliable in the long run.
|
|
0
|
|
|
|
Reply
|
A
|
5/10/2010 8:33:17 PM
|
|
On 2010-05-10, Todd <todd@invalid.com> wrote:
>>> Anyone know how to do a logical AND?
>>
>> cat xxx | grep -i abc | grep -i xyz
>>
>> Or is that "two lines of grep"?
>
> I am being a perfectionist and trying to get it
> all on one line. :'[
That _was_ all on one line.
--
Grant Edwards grant.b.edwards Yow! I have accepted
at Provolone into my life!
gmail.com
|
|
0
|
|
|
|
Reply
|
Grant
|
5/10/2010 8:50:14 PM
|
|
Todd <todd@invalid.com> writes:
>>> Figured out the logical AND, but not with grep:
>>>
>>> $ awk '/Nested/ && /Paging/' WS08-1.info.txt
>>> Nested Paging: off
>>>
>> :-)
>>
>> WE always used to reach for the awk manual when grep got silly.
>
> Do you know how to do it (with awk) case insensitive?
awk 'BEGIN {IGNORECASE=1} /nested/ && /paging/' WS08-1.info.txt
Vilmos
|
|
0
|
|
|
|
Reply
|
Vilmos
|
5/10/2010 10:02:18 PM
|
|
On 05/10/2010 01:50 PM, Grant Edwards wrote:
> On 2010-05-10, Todd<todd@invalid.com> wrote:
>
>>>> Anyone know how to do a logical AND?
>>>
>>> cat xxx | grep -i abc | grep -i xyz
>>>
>>> Or is that "two lines of grep"?
>>
>> I am being a perfectionist and trying to get it
>> all on one line. :'[
>
> That _was_ all on one line.
>
You are correct. I was trying to get it all in one statement.
Just being a perfectionist.
|
|
0
|
|
|
|
Reply
|
Todd
|
5/11/2010 5:11:41 PM
|
|
On 05/10/2010 03:02 PM, Vilmos Soti wrote:
> awk 'BEGIN {IGNORECASE=1}/nested/ && /paging/' WS08-1.info.txt
>
Cool. Thank you!
|
|
0
|
|
|
|
Reply
|
Todd
|
5/11/2010 5:12:37 PM
|
|
On 05/10/2010 01:33 PM, A Watcher wrote:
> I hate awk. The commmands are so cryptic that whomever tries to read the
> code later has to work at it to understand it.
I hear you there. I keep a list of examples. That is
the only way I remember.
|
|
0
|
|
|
|
Reply
|
Todd
|
5/11/2010 5:13:55 PM
|
|
On 05/11/10 13:11, Todd wrote:
> On 05/10/2010 01:50 PM, Grant Edwards wrote:
>> On 2010-05-10, Todd<todd@invalid.com> wrote:
>>
>>>>> Anyone know how to do a logical AND?
>>>>
>>>> cat xxx | grep -i abc | grep -i xyz
>>>>
>>>> Or is that "two lines of grep"?
>>>
>>> I am being a perfectionist and trying to get it
>>> all on one line. :'[
>>
>> That _was_ all on one line.
>>
>
> You are correct. I was trying to get it all in one statement.
> Just being a perfectionist.
cat xxx|grep -i abc
is 2 statements.
grep -i abc <xxx
is 1 statement.
|
|
0
|
|
|
|
Reply
|
Joe
|
5/11/2010 5:41:46 PM
|
|
The Natural Philosopher <tnp@invalid.invalid> wrote:
> Todd wrote:
> > On 05/10/2010 12:35 PM, Vilmos Soti wrote:
> >> Todd<todd@invalid.com> writes:
> >>
> >>> Without using two lines of grep, is there a way to
> >>> do a logical AND or OR with grep?
> >>
> >> You can do logical OR.
> >>
> >>> either abc or xyz
> >>>
> >>> cat xxx | grep -i abc OR xyz
> >>
> >> cat xxx | grep '\(abc\|xyz\)'
> >> cat xxx | grep -E '(abc|xyz)'
> >> cat xxx | egrep '(abc|xyz)'
> >>
> >>> or must have both
> >>>
> >>> cat xxx | grep -i abc AND xyz
> >>
> >> Not really.
> >>
> >> cat xxx | egrep '(abc.*xyz|xyz.*abc)'
> >>
> >> but this obviously doesn't scale...
> >>
> >> Vilmos
> >
> >
> > Thank you.
> >
> > Figured out the logical AND, but not with grep:
> >
> > $ awk '/Nested/ && /Paging/' WS08-1.info.txt
> > Nested Paging: off
> >
> :-)
>
> WE always used to reach for the awk manual when grep got silly.
Until perl, right?
--
PLEASE post a SUMMARY of the answer(s) to your question(s)!
Unless otherwise noted, the statements herein reflect my personal
opinions and not those of any organization with which I may be affiliated.
|
|
0
|
|
|
|
Reply
|
Kevin
|
5/11/2010 7:42:05 PM
|
|
Kevin the Drummer wrote:
> The Natural Philosopher <tnp@invalid.invalid> wrote:
>> Todd wrote:
>>> On 05/10/2010 12:35 PM, Vilmos Soti wrote:
>>>> Todd<todd@invalid.com> writes:
>>>>
>>>>> Without using two lines of grep, is there a way to
>>>>> do a logical AND or OR with grep?
>>>> You can do logical OR.
>>>>
>>>>> either abc or xyz
>>>>>
>>>>> cat xxx | grep -i abc OR xyz
>>>> cat xxx | grep '\(abc\|xyz\)'
>>>> cat xxx | grep -E '(abc|xyz)'
>>>> cat xxx | egrep '(abc|xyz)'
>>>>
>>>>> or must have both
>>>>>
>>>>> cat xxx | grep -i abc AND xyz
>>>> Not really.
>>>>
>>>> cat xxx | egrep '(abc.*xyz|xyz.*abc)'
>>>>
>>>> but this obviously doesn't scale...
>>>>
>>>> Vilmos
>>>
>>> Thank you.
>>>
>>> Figured out the logical AND, but not with grep:
>>>
>>> $ awk '/Nested/ && /Paging/' WS08-1.info.txt
>>> Nested Paging: off
>>>
>> :-)
>>
>> WE always used to reach for the awk manual when grep got silly.
>
> Until perl, right?
>
No.
Looked at Perl, and decided it was more opaque than C, and much larger
and useless than awk. But I didn't get involved in that sort of code
after that anyway. Left it to the minions ;-)
I was involved in system design not system admin.
|
|
0
|
|
|
|
Reply
|
The
|
5/11/2010 8:02:55 PM
|
|
On 2010-05-10, Vilmos Soti <vilmos@soti.ca> wrote:
> Todd <todd@invalid.com> writes:
>
>>>> Figured out the logical AND, but not with grep:
>>>>
>>>> $ awk '/Nested/ && /Paging/' WS08-1.info.txt
>>>> Nested Paging: off
>>>>
>>> :-)
>>>
>>> WE always used to reach for the awk manual when grep got silly.
>>
>> Do you know how to do it (with awk) case insensitive?
>
> awk 'BEGIN {IGNORECASE=1} /nested/ && /paging/' WS08-1.info.txt
>
> Vilmos
I think IGNORECASE is a gawk feature. For other awks you could write
awk 'tolower($0) ~ /nested/ && tolower($0) ~ /paging/'
|
|
0
|
|
|
|
Reply
|
Bill
|
5/22/2010 1:02:01 AM
|
|
|
18 Replies
1032 Views
(page loaded in 0.4 seconds)
Similiar Articles: tucows.comA place to access the latest and greatest Macintosh and Windows internet shareware, performance rated and checked for viruses. O.F. Mossberg & Sons, Inc. - Firearms, Shotguns, Rifles ...Shotguns and accessories made by this firm are discussed as well as information about discontinued models and parts. The GNU Operating SystemGNU Aris 1.8 Released: GNU Aris is a logical proof program. It supports both propositional and predicate logic, in addition to... more. GNOME Commit Digest, Issue 197: This ... OracleOracle engineers hardware and software to work together in the cloud and in your data center. Construction ManagementManaging Complexity. Building Trust. Mission Statement. We are a construction management firm committed to advancing, strengthening and sustaining all our relationships. CAREI - Colorado Association of Real Estate InvestorsColorado real estate is at its lowest point in nearly 20 years. Some see this as a problem, while others are quietly snatching up bargains and building huge fortunes ... The GRE: Graduate Record Examinationregister for the GRE ® revised General Test and start your future now. java.com: Java + YouGet the latest Java Software and explore how Java technology provides a better digital experience. Great Southern BankGreat Southern Bank is headquartered in Springfield, Missouri with locations found in St Louis, Kansas City, Columbia, & Joplin to name a few. Our offerings include a ... GEEP Global Electronic RecyclingGEEP works with its clients to set the best routes for recovring and recycling of a range of commercial and consumer products and reuse resources of the redundant ... Rosco Laboratories - United StatesColor correction and color filters, designer products, dance floors, fog systems, scenic paint, motion effects, patterns, Roscomurals, screens, stage hardware, and ... Employment Solutions - Greene ResourcesWe create workforce solutions that save money, increase efficiencies, decrease compliance risk and provide significant opportunities for profitability while ... GERD.com Landing PagePharmaceutical company sponsored site with information for suffers of chronic indigestion, or Gastroesophageal Reflux Disease. North Carolina State UniversityLearn more about North Carolina State University, located in Raleigh, N.C., and consistently recognized as one of the nation's top public universities. Free software downloads and software reviews - CNET Download.comCNET Download.com provides free downloads for Windows, Mac, iOS and Android computers and mobile devices. Every category of desktop software and mobile apps ... Logical conjunction - Wikipedia, the free encyclopediaIn logic and mathematics, a two-place logical operator and, also known as logical conjunction, results in true if both of its operands are true, otherwise the value ... Logical Operations - RalphB.net - Ralph Becker and his stuff on ...In the "truth tables" below, the input bits are in bold, and the results are plain. AND The logical AND operation compares 2 bits and if they are both "1", then the result ... 7/27/2012 9:56:32 AM
|