<?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: Assign a string to a Variable in Search Bar in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209018#M187796</link>
    <description>&lt;P&gt;Ok, if i understand you correct, you would like to dynamically extract Error messages from logs and assign it to a field? If yes, that is very much possible using eval&lt;/P&gt;

&lt;P&gt;You could you regular expressions to extract the Error string and assign it to field &lt;BR /&gt;
Syntax: ....|rex field=_raw "...(?P"Error...blah blah")" Refer: &lt;A href="http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/Rex"&gt;http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/Rex&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Using evals to look for Error and assign a generic value to the new Field. Example&lt;/P&gt;

&lt;P&gt;Syntax:  ....|eval Valid=if(match(_raw,"Error"),"Error","") etc (Endless possibilities here)&lt;/P&gt;

&lt;P&gt;Hope this leads you where you want to be &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Raghav&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jun 2016 15:19:34 GMT</pubDate>
    <dc:creator>Raghav2384</dc:creator>
    <dc:date>2016-06-13T15:19:34Z</dc:date>
    <item>
      <title>Assign a string to a Variable in Search Bar</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209017#M187795</link>
      <description>&lt;P&gt;I would like to assign a string to a variable, like valid ="error" then use the variable with the stats or timechart parameters, I have used eval command which is not working, really not sure which inbuilt variable command will help.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index="SubProduct" sourcetype="access_log" "Error due to validation" | timechart count by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is it possible to assign the string to a variable like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index="SubProduct" sourcetype="access_log" Valid = "Error due to validation" | timechart count(Valid) by host
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have used &lt;BR /&gt;
eval valid ="Error due to validation" command which is not working in this case.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 14:08:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209017#M187795</guid>
      <dc:creator>vkakani60</dc:creator>
      <dc:date>2016-06-13T14:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Assign a string to a Variable in Search Bar</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209018#M187796</link>
      <description>&lt;P&gt;Ok, if i understand you correct, you would like to dynamically extract Error messages from logs and assign it to a field? If yes, that is very much possible using eval&lt;/P&gt;

&lt;P&gt;You could you regular expressions to extract the Error string and assign it to field &lt;BR /&gt;
Syntax: ....|rex field=_raw "...(?P"Error...blah blah")" Refer: &lt;A href="http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/Rex"&gt;http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/Rex&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Using evals to look for Error and assign a generic value to the new Field. Example&lt;/P&gt;

&lt;P&gt;Syntax:  ....|eval Valid=if(match(_raw,"Error"),"Error","") etc (Endless possibilities here)&lt;/P&gt;

&lt;P&gt;Hope this leads you where you want to be &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Raghav&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 15:19:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209018#M187796</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2016-06-13T15:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Assign a string to a Variable in Search Bar</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209019#M187797</link>
      <description>&lt;P&gt;Does this help?&lt;BR /&gt;
index="SubProduct" sourcetype="access_log" "Error due to validation" | rex (?"Error due to validation") | timechart count(Valid) by host&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 15:25:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209019#M187797</guid>
      <dc:creator>sshelly_splunk</dc:creator>
      <dc:date>2016-06-13T15:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: Assign a string to a Variable in Search Bar</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209020#M187798</link>
      <description>&lt;P&gt;How you brought up the count(Valid) command without creating a Valid variable ? I want to achieve something like, assign a string to the variable called 'Value' then have to count the 'Value', technically I am counting the similar repeated string. &lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 19:44:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209020#M187798</guid>
      <dc:creator>vkakani60</dc:creator>
      <dc:date>2016-06-13T19:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: Assign a string to a Variable in Search Bar</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209021#M187799</link>
      <description>&lt;P&gt;I downvoted this post because misleading answer without structure.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 20:35:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209021#M187799</guid>
      <dc:creator>vkakani60</dc:creator>
      <dc:date>2016-06-13T20:35:10Z</dc:date>
    </item>
    <item>
      <title>Re: Assign a string to a Variable in Search Bar</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209022#M187800</link>
      <description>&lt;P&gt;for some reason, I cannot put in the exact search string ... use your search and pipe it to rex as described here: &lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/rex"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/rex&lt;/A&gt;&lt;BR /&gt;
Look at example 1. You are looking to create a single field, so use the first part of example 1. i got it to work, but for some reason, when I post my exact search string, it gets mashed up upon post.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 20:59:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Assign-a-string-to-a-Variable-in-Search-Bar/m-p/209022#M187800</guid>
      <dc:creator>sshelly_splunk</dc:creator>
      <dc:date>2016-06-13T20:59:59Z</dc:date>
    </item>
  </channel>
</rss>

