Using Grep to filter a text wave

Hi, 

I have a text wave (txtwave) containing a list of formulas. The formulas have CHNO elements in them but some formulas have only CHO elements. I want to extract formulas (with their index numbers) that have only CHNO vs formulas that have only CHO. I have been using Grep/INDX/Q/E to extract things that contain something but I don't know whether there is a way to use Grep to exclude things that contain something while listing the remaining. 

For example: I can do Grep/INDX/Q/E="N" txtwave  and it will give me W_Index for all formulas containing CHNO. 

However, how can I extract formulas that do not contain N? 

Sincerely, 

Peeyush

Here is a snippet from the Grep help:

/E={regExprStr, reverse }
Specifies the Perl-compatible regular expression string, regExprStr, for which the sense of the match can be changed by reverse.
reverse=1:  Matching expressions are taken to not match, and vice versa. For example, use /E={"CheckBox",1} to list all lines that do not contain "CheckBox".
reverse=0:  Same as just /E=regExptrStr.

and

To copy lines that do not match the regular expression, set the /E flag's reverse parameter:
// Copy lines that do NOT contain "Fred", "fred", "fREd", etc
Grep/P=myPath/E={"(?i)fred",1} "afile.txt" as "NotFredFile.txt"

 

wow this is super cool! Thanks a lot, chozo! While we are at this, is there a way to set two parameters? So, if I want to say exclude everything that contains "N" and "O" both, is there a one-liner for this? I tried Grep/INDX/Q/E={"N","O",1} txtwave but this doesn't work..  

 

Also, just for my understanding, when I write Grep/INDX/Q/E="N" txtwave, that's just the short form of saying Grep/INDX/Q/E={"N",0} txtwave. Is this correct? that there is no logical difference between the two statements

In reply to by Peeyush Khare

Peeyush Khare wrote:

is there a one-liner for this?

With grep the answer is pretty much always yes. My starting point is usually to search the web for 'regex' together with whatever I want to do. There are a lot of resources out there, regex testing engines and discussion boards filled with regex questions and answers. I strongly encourage taking a moment to look there as a first point of call when you have a regular expression question.

Note that you can use multiple regex flags with grep.

"N.*O|O.*N" is one way to say match both O and N.

 

 

Thanks a lot, Tony! I didn't know about the regex pages. From here on, I'll check there first. Thanks for the syntax!