<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to use the foreach command to list a particular field that contains an email address? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266228#M51027</link>
    <description>&lt;P&gt;Maybe it's too simple but try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search | rex "(?&amp;lt;myQP&amp;gt;QP_\w).\w+@[^,]*" | table myQP
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
    <pubDate>Thu, 20 Oct 2016 08:50:09 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2016-10-20T08:50:09Z</dc:date>
    <item>
      <title>How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266223#M51022</link>
      <description>&lt;P&gt;I have events in JSON format as follows -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event 1: 
{ QP_A:abc@gmail.com, QP_B:123, COUNTRY:USA}
Event 2: 
{ QP_C:XYZ@gmail.com, QP_B:123, COUNTRY:USA}
Event 3: 
{ QP_f:100, QP_Bb:123, COUNTRY:USA}
Event 4: 
{ COUNTRY:USA, STATE:CT}
Event 5: 
{ QP_A[0][A]:abc@gmail.com, COUNTRY:USA, STATE:CT}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Observe that &lt;CODE&gt;QP_*&lt;/CODE&gt; fields don't appear in all events and even if they did they may not have a field that has an email address.&lt;/P&gt;

&lt;P&gt;I am trying to search and list all &lt;CODE&gt;QP_*&lt;/CODE&gt; fields that have email addresses in them. How can I do it?&lt;/P&gt;

&lt;P&gt;I tried using &lt;CODE&gt;foreach&lt;/CODE&gt; command, but no luck in the syntax -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc  QP_*  
| foreach QP_* [eval fieldnames = if(match(&amp;lt;&amp;gt;, ".com"), "&amp;lt;&amp;gt;", "NoMatch")] | table _raw fieldnames
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I see the output (may be wrong but) I see error that says something like - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[splunkindxers-001] Failed to parse templatized search for field 'QP_A[0][A]'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output I am looking for in case of my above events is - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;QP_A
QP_C
QP_A[0][A]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 21:08:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266223#M51022</guid>
      <dc:creator>jagadeeshm</dc:creator>
      <dc:date>2016-10-19T21:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266224#M51023</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search | rex "{\s(?&amp;lt;emfield&amp;gt;[^:]+):.*@"  | table emfield
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Oct 2016 21:27:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266224#M51023</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-10-19T21:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266225#M51024</link>
      <description>&lt;P&gt;It did not pick anything. I can see one column emfield with no values in it.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 21:30:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266225#M51024</guid>
      <dc:creator>jagadeeshm</dc:creator>
      <dc:date>2016-10-19T21:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266226#M51025</link>
      <description>&lt;P&gt;Did you use the '&amp;lt;&amp;gt;' in the foreach command?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc  QP_*  
 | foreach QP_* [eval fieldnames = if(match('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', ".com"), "&amp;lt;&amp;gt;", "NoMatch")] | table _raw fieldnames
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Oct 2016 21:44:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266226#M51025</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2016-10-19T21:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266227#M51026</link>
      <description>&lt;P&gt;What about this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=abc  QP_*  
| eval fieldnames = ""
| foreach QP_* [eval temp = if(match('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', "^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$"), "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;;", "") | eval fieldnames = fieldnames . temp]
| eval fieldnames = split(fieldnames, ";")
| table _raw fieldnames
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I replicated your problem in my lab it seemed to work fine. See below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval raw = split("{ \"QP_A\":\"abc@gmail.com\", \"QP_B\":\"abc@gmail.com\", \"COUNTRY\":\"abc@gmail.com\"};{ \"QP_F\":\"abcgmail.com\", \"QP_G\":\"abcgmail.com\", \"COUNTRY\":\"abcgmail.com\"};{ \"QP_C\":\"XYZ@gmail.com\", \"QP_B\":\"123\", \"COUNTRY\":\"USA\"}", ";")
| mvexpand raw
| rename raw as _raw
| spath
| eval fieldnames = ""
| foreach QP_* [eval temp = if(match('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', "^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$"), "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;;", "") | eval fieldnames = fieldnames . temp]
| eval fieldnames = split(fieldnames, ";")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output: see picture&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2046i7175B50AF530032E/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2016 21:52:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266227#M51026</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-10-19T21:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266228#M51027</link>
      <description>&lt;P&gt;Maybe it's too simple but try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search | rex "(?&amp;lt;myQP&amp;gt;QP_\w).\w+@[^,]*" | table myQP
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Thu, 20 Oct 2016 08:50:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266228#M51027</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2016-10-20T08:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266229#M51028</link>
      <description>&lt;P&gt;Is there a way to get fields and their respective values separately ?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 12:41:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266229#M51028</guid>
      <dc:creator>jagadeeshm</dc:creator>
      <dc:date>2016-10-21T12:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266230#M51029</link>
      <description>&lt;P&gt;You mean something like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your previous search
| foreach QP_* [eval temp = if(match('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', "^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$"), "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=".&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;.";", "") | eval fieldnames = fieldnames . temp]
| eval fieldnames = split(fieldnames, ";")
| table _raw fieldnames
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;QP_A=abc@gmail.com
QP_B=abc@gmail.com 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All I've changed is "&amp;lt;&amp;gt;;" with "&amp;lt;&amp;gt;=".&amp;lt;&amp;gt;.";"&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 13:24:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266230#M51029</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-10-21T13:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266231#M51030</link>
      <description>&lt;P&gt;Woh, that worked. I am still trying to understand how the match returned the email address! &lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 14:31:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266231#M51030</guid>
      <dc:creator>jagadeeshm</dc:creator>
      <dc:date>2016-10-21T14:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266232#M51031</link>
      <description>&lt;P&gt;It basically translates to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;IF 
    THE_VALUE_OF_YOUR_FIELD_CAPTURED_WITH_FOREACH ('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;')
MATCHES
    EMAIL REGEX (^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$)
THEN
    "FIELD NAME = CONCATENATED WITH FIELD VALUE AND SEMICOLON" ("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=".&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;.";")
ELSE
    EMPTY STRING
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that's clear enough.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Oct 2016 16:58:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266232#M51031</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-10-21T16:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266233#M51032</link>
      <description>&lt;P&gt;I am unable to get the values for my fields using this example.  While I am able to successfully return only the fields I want, when editing to return the values, I just get &lt;BR /&gt;
Failed to parse templatized search for field ***&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 19:59:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/266233#M51032</guid>
      <dc:creator>Cuyose</dc:creator>
      <dc:date>2018-10-10T19:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the foreach command to list a particular field that contains an email address?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/535947#M89861</link>
      <description>&lt;P&gt;actualy that has give me some idea, extract data without some words. it's worked. thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;| rex field=domain "(?P&amp;lt;s&amp;gt;[^blabla.com].+)"&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2021 06:26:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-use-the-foreach-command-to-list-a-particular-field-that/m-p/535947#M89861</guid>
      <dc:creator>murataydogan</dc:creator>
      <dc:date>2021-01-15T06:26:29Z</dc:date>
    </item>
  </channel>
</rss>

