<?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 Extract the same field two different ways in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-the-same-field-two-different-ways/m-p/33720#M178304</link>
    <description>&lt;P&gt;I want to end up with a filed called mapi_err that contains a MAPI error string. I am looking at the third line in a multi-line event which may look like:&lt;/P&gt;

&lt;P&gt;Unpopulated address list - can't resolve names: MAPI_E_NOT_FOUND&lt;/P&gt;

&lt;P&gt;or it may look like&lt;/P&gt;

&lt;P&gt;Unable to create MAPI message in Outbox, HR=80040115&lt;/P&gt;

&lt;P&gt;In the first case, the error string is in the event, MAPI_E_NOT_FOUND, so I can just extract any ": MAPI_*". In the second case, I need to extract the hex error code, 80040115, after "HR=" and then do a lookup in a CSV to get the MAPI error string. I can't figure out a way to accommodate both event formats in a search string. I've gotten the full line into mapi_err_full and then tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=mapi_err_full ": (?&amp;amp;lt;mapi_err&amp;gt;MAPI_.*)" | rex field=mapi_err_full "HR=(?&amp;amp;lt;mapi_err_hex&amp;gt;[0-9]+)" | lookup MAPIErrorCodes "Hex" as mapi_err_hex OUTPUT "Code" as mapi_err
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I really only want to do the lookup if mapi_err_hex is defined. Otherwise, when the lookup fails for events without a mapi_err_hex, it destroys the good value already in mapi_err. Do I have to resort to two separate extractions in props.conf?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 12:15:28 GMT</pubDate>
    <dc:creator>tstanley</dc:creator>
    <dc:date>2020-09-28T12:15:28Z</dc:date>
    <item>
      <title>Extract the same field two different ways</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-the-same-field-two-different-ways/m-p/33720#M178304</link>
      <description>&lt;P&gt;I want to end up with a filed called mapi_err that contains a MAPI error string. I am looking at the third line in a multi-line event which may look like:&lt;/P&gt;

&lt;P&gt;Unpopulated address list - can't resolve names: MAPI_E_NOT_FOUND&lt;/P&gt;

&lt;P&gt;or it may look like&lt;/P&gt;

&lt;P&gt;Unable to create MAPI message in Outbox, HR=80040115&lt;/P&gt;

&lt;P&gt;In the first case, the error string is in the event, MAPI_E_NOT_FOUND, so I can just extract any ": MAPI_*". In the second case, I need to extract the hex error code, 80040115, after "HR=" and then do a lookup in a CSV to get the MAPI error string. I can't figure out a way to accommodate both event formats in a search string. I've gotten the full line into mapi_err_full and then tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex field=mapi_err_full ": (?&amp;amp;lt;mapi_err&amp;gt;MAPI_.*)" | rex field=mapi_err_full "HR=(?&amp;amp;lt;mapi_err_hex&amp;gt;[0-9]+)" | lookup MAPIErrorCodes "Hex" as mapi_err_hex OUTPUT "Code" as mapi_err
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I really only want to do the lookup if mapi_err_hex is defined. Otherwise, when the lookup fails for events without a mapi_err_hex, it destroys the good value already in mapi_err. Do I have to resort to two separate extractions in props.conf?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:15:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-the-same-field-two-different-ways/m-p/33720#M178304</guid>
      <dc:creator>tstanley</dc:creator>
      <dc:date>2020-09-28T12:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the same field two different ways</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-the-same-field-two-different-ways/m-p/33721#M178305</link>
      <description>&lt;P&gt;See if this works for you , extract the first case to "mapi_err_1" and the hex code lookup to "mapi_err_2" , then coalesce the results into the field "mapi_err"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval mapi_err=coalesce(mapi_err_1, mapi_err_2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:15:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-the-same-field-two-different-ways/m-p/33721#M178305</guid>
      <dc:creator>Damien_Dallimor</dc:creator>
      <dc:date>2020-09-28T12:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the same field two different ways</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-the-same-field-two-different-ways/m-p/33722#M178306</link>
      <description>&lt;P&gt;Ahh, yes, exactly what I was looking for. I was thinking about an if() statement or field aliasing, some way to choose between two values or to combine them. I didn't know about coalesce. Works great, thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Aug 2012 15:27:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-the-same-field-two-different-ways/m-p/33722#M178306</guid>
      <dc:creator>tstanley</dc:creator>
      <dc:date>2012-08-14T15:27:59Z</dc:date>
    </item>
  </channel>
</rss>

