Artificial intelligent assistant

How do i concatenate these two grep regexes I have these two grep regexes grep -e '[Yy].*[Yy].[Ee][Ee]' first.txt and grep -e '[Ee][Ee].*[Yy].*[Yy]' first.txt How do I concatenate these two into a single regex?

By.. concatenating the patterns?


grep -e '[Yy].*[Yy].[Ee][Ee][Ee][Ee].*[Yy].*[Yy]' first.txt


Or did you mean essentially doing a logical AND of the two patterns?

If the latter, you need to fake it, as while `grep` has built-in OR (`|`) and NOT (`-v`; `[^]`), it does not have a built-in AND. One way is by piping the output of one `grep` into the other:


grep -e '[Yy].*[Yy].[Ee][Ee]' first.txt | grep '[Ee][Ee].*[Yy].*[Yy]'


The other way is to look for both patterns in series, in either order, with a logical OR (abbreviated for brevity):


grep -Ee 'pattern1.*pattern2|pattern2.*pattern1' input.txt


I find the first to be more succinct and easier to maintain.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 8e0860849f9049efcfd525f8bfe1640f