[Top][All Lists]

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

bug#37754: wish for grep --and -eX -eY -eZ (X∩Y∩Z intersection, not X∪Y∪

From: Trent W. Buck
Subject: bug#37754: wish for grep --and -eX -eY -eZ (X∩Y∩Z intersection, not X∪Y∪Z union)
Date: Thu, 17 Oct 2019 11:19:54 +1100
User-agent: Mutt/1.10.1 (2018-07-13)

Paul Eggert wrote:
> Wouldn't it be more useful to have an intersection operator in regular
> expressions? That is, the pattern 'A\&B' would match anything that is
> matched by both A and B. If A and B have parenthesized subexpressions, both
> sets of parentheses would match and would count.

Not for me personally, because I almost always want to use it with -Fwi :-)

(-F is a lot faster - about as fast as LC_COLLATE - and it also means
I don't have to think about escaping special characters.)

> [...]
> This approach would allow intersection to be nested inside other operations.
> Also, it would clarify how other features work. For example, grep -o has
> clear semantics with this approach, whereas the semantics of grep -o are not
> so clear with the proposed --and option.

I hadn't thought about -o, and I agree that is not very obvious.

Given an input file like

   30$  Gamdias EROS (M2) USB Multi-Color Lighting Gaming Headset
   30$  Gamdias POSEIDON E1 Gaming Combo 3-in-1 K/B+3200dpi Optical 
Mouse+Stereo Headset
   30$  GeIL (GP34GB1600C11SC) 4GB DDR3 1600 Desktop RAM
   30$  GeIL Pristine (GP44GB2400C17SC) 4GB Single DDR4 2400 Desktop RAM
   30$  GeIL SO-DIMM 4GB (GGS34GB1600C11SC) 1.35V (Low Voltage) 4GB DDR3 1600 
Notebook Ram

Where currently "grep -Fw -e 4GB -e DDR4 -o" prints


I would expect "grep -Fw -e 4GB -e DDR4 --and" to print the same thing as

    grep -Fw 4GB | grep -Fw DDR4 | grep -Fw -e 4GB -e DDR4 -o



reply via email to

[Prev in Thread] Current Thread [Next in Thread]