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:
and
March 24, 2022 at 06:20 am - Permalink
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
March 24, 2022 at 07:19 am - Permalink
In reply to wow this is super cool!… by Peeyush Khare
[quote=Peeyush Khare]
is there a one-liner for this?
[/quote]
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.
March 24, 2022 at 08:42 am - Permalink
Thanks a lot, Tony! I didn't know about the regex pages. From here on, I'll check there first. Thanks for the syntax!
March 24, 2022 at 08:50 am - Permalink
In reply to Thanks a lot, Tony! I didn't… by Peeyush Khare
I have found the igor help to be a pretty thorough resource as well:
DisplayHelpTopic("Basic Regular Expressions")March 24, 2022 at 10:30 am - Permalink
In reply to I have found the igor help… by KurtB
Thanks a lot for the tip, KurtB!
March 24, 2022 at 04:57 pm - Permalink