How do i concatenate these two grep regexes

Mel Rossi

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?

DopeGhoti

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I concatenate two IntStreams?

How do I concatenate two strings in Java?

How do I concatenate two slices in Rust?

How do I concatenate two lists in Python?

How do I concatenate two strings in C?

How do I concatenate two arrays in php?

How do I concatenate two lists inside nested list Python?

How do I concatenate two vectors with one line of code

How do I fit the model of two concatenate LSTM in keras?

How do I concatenate two arrays in C#?

How do I concatenate the content of two files to make a third?

How do I concatenate two arrays of different datatypes in BigQuery?

How do I concatenate two fields in n1ql?

How do I concatenate two arrays in this specific way

How do I concatenate two string macros in C?

How do I concatenate two lists together but with different frequencies

How do I finish this loop? Concatenate two previous characters

How do I grep for "->"?

How do I concatenate strings?

Why do regexes function differently in dplyr v. grep()

How can I concatenate two LSTM with Keras?

how can I concatenate two arrays in javascript?

When replacing with regexes, how do I append digits to the end of a match group?

In R, how do I apply regexes to specific parts of a string that contains a pattern?

How can I write an alias of Raku regexes?

How can I split at word boundaries with regexes?

How can i make an array of regexes in Golang?

How do I make a type annotation for a list of subclass instances, e.g to concatenate two lists?

How do I concatenate two lists while taking elements 1 by 1