<?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: REX with a variable rather than a string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191736#M55195</link>
    <description>&lt;P&gt;Answering regular-expression-based questions without a look at the (anonymized?) raw data is nigh-on impossible, even for us &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Using a field value probably isn't going to work, but there might be an entirely different way to solve the issue.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Aug 2014 11:53:21 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-08-22T11:53:21Z</dc:date>
    <item>
      <title>REX with a variable rather than a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191735#M55194</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;I have a large chunk of raw data from one of my servers and am trying to filter the data down using a multiple REX statements.&lt;/P&gt;

&lt;P&gt;From the data, I run a REX to return my first value, for example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mysearch | rex"ProcessID:(?&amp;lt;PROCESS&amp;gt;)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works fine and I can see that the value is correct.  I would then like to use the value of PROCESS in a further REX statement:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;searchAsAbovve | rexAsAbove | rex "&amp;lt;PROCESS&amp;gt;(?&amp;lt;CPU&amp;gt;)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have tried multiple variations but I believe the PROCESS value is being input as a string rather than taking the value extracted from the previous REX.  &lt;/P&gt;

&lt;P&gt;Can anyone advise if there is a way to tell Splunk that the second REX is using a variable rather than a string?  I have also tried using EVAL, for example eval "ProcID"=PROCESS then using the eval field in my REX statement but appear to get the same result.&lt;/P&gt;

&lt;P&gt;Perhaps there is a better way of achieving this.&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 11:51:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191735#M55194</guid>
      <dc:creator>PhilAndreotti</dc:creator>
      <dc:date>2014-08-22T11:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: REX with a variable rather than a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191736#M55195</link>
      <description>&lt;P&gt;Answering regular-expression-based questions without a look at the (anonymized?) raw data is nigh-on impossible, even for us &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Using a field value probably isn't going to work, but there might be an entirely different way to solve the issue.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 11:53:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191736#M55195</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-22T11:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: REX with a variable rather than a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191737#M55196</link>
      <description>&lt;P&gt;Thanks Martin, good point and  I'll try to elaborate with the extract below:&lt;/P&gt;

&lt;P&gt;SNMPv2-SMI::mib-2."25.4.2.1.2.1127" = "upstart-socket-" SNMPv2-SMI::mib-2."25.5.1.1.2.1127" = "388" SNMPv2-SMI::mib-2."25.4.2.1.2.1134" = "rsyslogd" SNMPv2-SMI::mib-2."25.5.1.1.2.1134" = "1576" SNMPv2-SMI::mib-2."25.4.2.1.2.1173" = "dbus-daemon" SNMPv2-SMI::mib-2."25.5.1.1.2.1173" = "988" SNMPv2-SMI::mib-2."25.4.2.1.2.1271" = "kworker/9:2" SNMPv2-SMI::mib-2."25.5.1.1.2.1271" = "0" SNMPv2-SMI::mib-2."25.4.2.1.2.1320" = "sshd" SNMPv2-SMI::mib-2."25.5.1.1.2.1320" = "2928"&lt;BR /&gt;
Next comment will have details due to char limit&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 12:18:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191737#M55196</guid>
      <dc:creator>PhilAndreotti</dc:creator>
      <dc:date>2014-08-22T12:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: REX with a variable rather than a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191738#M55197</link>
      <description>&lt;P&gt;The extract is an SNMP query from a server.  It returns the process ID's and the RAM used for each.  I am using an initial REX to identify the PID, then I need to use the PID to identify the RAM used. i.e.&lt;/P&gt;

&lt;P&gt;REX to identify the PID of rsyslogd would = 1134.&lt;/P&gt;

&lt;P&gt;I then use EVAL or direct in to another REX to add the PID to the following SNMP query to determine the number that is returned after SNMPv2-SMI::mib-2."25.5.1.1.2.1134" = " which is 1576.  This is the RAM used for this particular process.&lt;/P&gt;

&lt;P&gt;As the PID will change on each boot, I need to search for the unique PID every time for accuracy.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 12:22:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191738#M55197</guid>
      <dc:creator>PhilAndreotti</dc:creator>
      <dc:date>2014-08-22T12:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: REX with a variable rather than a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191739#M55198</link>
      <description>&lt;P&gt;Here's a thought:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "(?&amp;lt;PID&amp;gt;\d+)\" = \"rsyslogd\"" | eval RAM = replace(_raw, ".*" + PID + "\" = \"(\d+)\".*", "\1") | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That'll extract the 1134 before "rsyslogd" and use that in the &lt;CODE&gt;replace()&lt;/CODE&gt; to locate the number after the equals sign, replacing the entire string with just that number - effectively extracting the field.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 12:31:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191739#M55198</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-22T12:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: REX with a variable rather than a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191740#M55199</link>
      <description>&lt;P&gt;This worked perfectly thank you.  Now I'm just trying to understand exactly what is going on rather than just use the answer but I've done a few tests and it seems to be doing exactly what I need so thank you very much&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 13:06:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191740#M55199</guid>
      <dc:creator>PhilAndreotti</dc:creator>
      <dc:date>2014-08-22T13:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: REX with a variable rather than a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191741#M55200</link>
      <description>&lt;P&gt;The key here is to work around the apparent shortcoming of &lt;CODE&gt;rex&lt;/CODE&gt; - static regex strings with no field value replacement - and achieve the same thing with &lt;CODE&gt;eval&lt;/CODE&gt; that obviously can use field values.&lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;replace()&lt;/CODE&gt;'s regex matches the entire &lt;CODE&gt;_raw&lt;/CODE&gt; event, replacing everything with the content of the first capturing group - the RAM usage.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2014 14:37:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/REX-with-a-variable-rather-than-a-string/m-p/191741#M55200</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-08-22T14:37:02Z</dc:date>
    </item>
  </channel>
</rss>

