<?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 search a matching string using lookup? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389859#M113592</link>
    <description>&lt;P&gt;Thanks for your reply. It got me a bit further but I'm still doing something wrong. &lt;BR /&gt;
Here is the updated lookup table using wildcards:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; longtext,shorttext
*message aaa*,ma
*message bbb*,mb
*message ccc*,mc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I then ran the following query to display the message and its corresponding shorttext:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=source1 | rex "...(?&amp;lt;message&amp;gt;\S*)..." | lookup messages.csv longtext as message OUTPUT shorttext | table message, shorttext
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This returns some results with the message field, but not the shorttext lookup:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;message,shorttext
this is a long message aaa example,
this is a long message ccc example,
this is a long message aaa example,
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 14 May 2018 16:41:41 GMT</pubDate>
    <dc:creator>equick</dc:creator>
    <dc:date>2018-05-14T16:41:41Z</dc:date>
    <item>
      <title>How to search a matching string using lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389857#M113590</link>
      <description>&lt;P&gt;I have a query like this, which prints the number of message matches and an abbreviation:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=source1 | rex "...(?&amp;lt;message&amp;gt;\S*)..." | eval message=case(like(message, "%message aaa%), "ma", like(message, "%message bbb%"), "mb", like(message, "%message ccc%", "mc", 1=1, message) | stats count by message
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ma 4
mb 1
mc 18
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However as I add more messages to the search it's becoming too long so I'm trying to switch to using a lookup table.&lt;/P&gt;

&lt;P&gt;I have created a csv lookup called messages.csv (example below) :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;longtext,shorttext
message aaa,ma
message bbb,mb
message ccc,mc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and tried various queries including the below but they all fail so was hoping someone here might be able to give me a hint:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=source1 | rex "...(?&amp;lt;message&amp;gt;\S*)..." | search [ | inputlookup messages.csv | fields longtext | rename longtext as message] | lookup messages.csv output shorttext | stats count by shorttext
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance,&lt;BR /&gt;
Ed&lt;/P&gt;</description>
      <pubDate>Sun, 13 May 2018 17:23:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389857#M113590</guid>
      <dc:creator>equick</dc:creator>
      <dc:date>2018-05-13T17:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to search a matching string using lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389858#M113591</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;

&lt;P&gt;the easiest way should be a wildcard lookup, you can find a good explanation on that topic in this answer:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/52580/can-we-use-wildcard-characters-in-a-lookup-table.html"&gt;https://answers.splunk.com/answers/52580/can-we-use-wildcard-characters-in-a-lookup-table.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You just need to switch the lookup type to wildcard, and append/prepend an &lt;CODE&gt;*&lt;/CODE&gt; to your message text. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Hope that helps - if it does I'd be happy if you would upvote/accept this answer, so others could profit from it. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 13 May 2018 20:37:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389858#M113591</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-05-13T20:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to search a matching string using lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389859#M113592</link>
      <description>&lt;P&gt;Thanks for your reply. It got me a bit further but I'm still doing something wrong. &lt;BR /&gt;
Here is the updated lookup table using wildcards:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; longtext,shorttext
*message aaa*,ma
*message bbb*,mb
*message ccc*,mc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I then ran the following query to display the message and its corresponding shorttext:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=source1 | rex "...(?&amp;lt;message&amp;gt;\S*)..." | lookup messages.csv longtext as message OUTPUT shorttext | table message, shorttext
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This returns some results with the message field, but not the shorttext lookup:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;message,shorttext
this is a long message aaa example,
this is a long message ccc example,
this is a long message aaa example,
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 May 2018 16:41:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389859#M113592</guid>
      <dc:creator>equick</dc:creator>
      <dc:date>2018-05-14T16:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to search a matching string using lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389860#M113593</link>
      <description>&lt;P&gt;Did you change the type of the lookup to a wildcard lookup? &lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 17:54:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389860#M113593</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-05-14T17:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to search a matching string using lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389861#M113594</link>
      <description>&lt;P&gt;Could you give me an example of what you mean by that please? I understood that to mean I needed to put wildcards around the longtext values in messages.csv&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 18:09:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389861#M113594</guid>
      <dc:creator>equick</dc:creator>
      <dc:date>2018-05-14T18:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to search a matching string using lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389862#M113595</link>
      <description>&lt;P&gt;Basically you've to first create a lookup table file (extension .csv) with those wildcard characters around the message field values (which you did) and then create lookup definition (See below link) with MATCH type as WILDCARD. Please note that if you've using Splunk 6.5 or above, you get the MatchType option in Splunk Web UI. If you're using lower Splunk version than that, you'd need to configure that via configuration files on SH (transforms.conf). &lt;BR /&gt;
Once all those steps are done, do the&lt;CODE&gt;| lookup&lt;/CODE&gt;  using lookup definition.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.0/Knowledge/Usefieldlookupstoaddinformationtoyourevents#Create_a_CSV_lookup_definition"&gt;http://docs.splunk.com/Documentation/Splunk/7.1.0/Knowledge/Usefieldlookupstoaddinformationtoyourevents#Create_a_CSV_lookup_definition&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 18:50:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389862#M113595</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-05-14T18:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to search a matching string using lookup?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389863#M113596</link>
      <description>&lt;P&gt;Amazing thank you! I was completely oblivious to lookup definitions. I added that and now the lookup works a treat! Thank you both for your answers, and taking the time to help me. I really appreciate it.&lt;/P&gt;

&lt;P&gt;Ed&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 08:07:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-a-matching-string-using-lookup/m-p/389863#M113596</guid>
      <dc:creator>equick</dc:creator>
      <dc:date>2018-05-15T08:07:29Z</dc:date>
    </item>
  </channel>
</rss>

