<?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 create a custom field to match a particular string? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308116#M58006</link>
    <description>&lt;P&gt;This was the best solution, it just wasn't a great one but it worked.  I believe it's the best solution given the limitations of the core tool. &lt;/P&gt;</description>
    <pubDate>Thu, 20 Apr 2017 12:40:57 GMT</pubDate>
    <dc:creator>jwelters</dc:creator>
    <dc:date>2017-04-20T12:40:57Z</dc:date>
    <item>
      <title>How to create a custom field to match a particular string?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308109#M57999</link>
      <description>&lt;P&gt;I have an interesting use case, where I have a list of strings that I search for within our proxy logs to identify problem systems. This works quite well. Currently the list exists in both a CSV format, and a search Macro. The macro just specifies (phrase1 OR phrase2 OR phrase3) it's not complicated. &lt;/P&gt;

&lt;P&gt;Recently I decided I wanted to add to our analysis and return the results but also figure out how to add a new field that is the particular string that was matched. For example if the phrase was infected, I could display a table with the _time, URL , and  matched_string.   This would make analysis a bit easier for us. &lt;/P&gt;

&lt;P&gt;I've seen a couple ways folks have looked at doing something similar but I wasn't able to find a working solution for me, has anyone done something like this before ? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:54:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308109#M57999</guid>
      <dc:creator>jwelters</dc:creator>
      <dc:date>2020-09-29T12:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom field to match a particular string?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308110#M58000</link>
      <description>&lt;P&gt;How many keywords are there? I'm assuming there are low as you are using them in Macro. If that's still the case, you could write another macro, which will do like this. You'd end up maintaining two macros and have to update both when you add a new phrase.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; eval matched_string=case(searchmatch("phrase1"),"phrase1",searchmatch("phrase2"),"phrase2", searchmatch("phrase3"),"phrase3",...,1=1,"PhraseNotInMacro")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Feb 2017 20:29:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308110#M58000</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-02-17T20:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom field to match a particular string?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308111#M58001</link>
      <description>&lt;P&gt;Here's a sample of what you can do.  This makes a list (you would substitute your lookup table here) &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults |eval mylist="infected disturbed reallycrazy zombiefied"|makemv mylist | mvexpand mylist 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this turns it into a tight regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|rename mylist as search
|format "(?&amp;lt;resultfield&amp;gt;" "" 3 "" "|" ")" 
| rex field=search mode=sed "s/\&amp;gt;  /\&amp;gt;/g" 
| rex field=search mode=sed "s/  \|  /|/g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The return value looks like this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;resultfield\&amp;gt;infected|disturbed|reallycrazy|zombiefied )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and you can drop that into a rex command &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw max_match=5 [the above search using your lookup table as input]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to extract which of the lookup item(s) matched. &lt;/P&gt;</description>
      <pubDate>Sat, 18 Feb 2017 00:07:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308111#M58001</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-18T00:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom field to match a particular string?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308112#M58002</link>
      <description>&lt;P&gt;There are a few hundred. &lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 13:28:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308112#M58002</guid>
      <dc:creator>jwelters</dc:creator>
      <dc:date>2017-02-21T13:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom field to match a particular string?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308113#M58003</link>
      <description>&lt;P&gt;My bet will be on creating a macro with case expressions similar to above, assuming the phrase can occur at any place in the raw data (no fixed position).&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 15:45:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308113#M58003</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-02-21T15:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom field to match a particular string?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308114#M58004</link>
      <description>&lt;P&gt;It looks like this will work well, as there's already a script that creates the Search macro, and the lookup table... it's fairly easy to also have it create the macro for this. &lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 16:28:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308114#M58004</guid>
      <dc:creator>jwelters</dc:creator>
      <dc:date>2017-02-21T16:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom field to match a particular string?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308115#M58005</link>
      <description>&lt;P&gt;@jwelters - Did one of the answers below help provide a solution your question? If yes, please click “Accept” below the best answer to resolve this post and upvote anything that was helpful. If no, please leave a comment with more feedback. Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2017 23:39:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308115#M58005</guid>
      <dc:creator>aaraneta_splunk</dc:creator>
      <dc:date>2017-04-19T23:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a custom field to match a particular string?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308116#M58006</link>
      <description>&lt;P&gt;This was the best solution, it just wasn't a great one but it worked.  I believe it's the best solution given the limitations of the core tool. &lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 12:40:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-create-a-custom-field-to-match-a-particular-string/m-p/308116#M58006</guid>
      <dc:creator>jwelters</dc:creator>
      <dc:date>2017-04-20T12:40:57Z</dc:date>
    </item>
  </channel>
</rss>

