<?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: Creating new fields using rex lookup in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Creating-new-fields-using-rex-lookup/m-p/103446#M26738</link>
    <description>&lt;P&gt;Thanks! That will do the trick nicely! Simple and effective...&lt;/P&gt;</description>
    <pubDate>Wed, 28 Mar 2012 22:21:20 GMT</pubDate>
    <dc:creator>monkey</dc:creator>
    <dc:date>2012-03-28T22:21:20Z</dc:date>
    <item>
      <title>Creating new fields using rex lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-new-fields-using-rex-lookup/m-p/103444#M26736</link>
      <description>&lt;P&gt;I've got a situation where I'm trying to use rex to create a new field but I can't quite get it to work. And I'd really appreciate some help.&lt;/P&gt;

&lt;P&gt;I have a field called foo which is made up of two values concatenated together and right padded with zero.&lt;/P&gt;

&lt;P&gt;So foo = value1.value2, where value1 is 1 to 11 and value2 is four digits long. E.g.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo=165730 - value1: 1, value2: 6573
foo=265730 - value1: 2, value2: 6573
foo=365730 - value1: 3, value2: 6573
foo=465730 - value1: 4, value2: 6573
foo=565730 - value1: 5, value2: 6573
foo=665730 - value1: 6, value2: 6573
foo=765730 - value1: 7, value2: 6573
foo=865730 - value1: 8, value2: 6573
foo=965730 - value1: 9, value2: 6573
foo=106573 - value1: 10, value2: 6573
foo=116573 - value1: 11, value2: 6573
etc.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I want to create a new field based on a lookup on value1, such that&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;If value1=1, newfield=THINGONE
If value1=2, newfield=THINGTWO
...
If value1=11, newfield=THINGELEVEN
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can completely replace the value of foo by stringing together a load of rex'es as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex mode=sed field=foo "s/(^10[0-9]{4}$)/THINGTEN/g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or I can filter out just one field at a time with the following...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| regex foo="^10[0-9]{4}$(?&amp;lt;newfield&amp;gt;THINGTEN)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I just can't work out how to &lt;EM&gt;keep&lt;/EM&gt; the value in foo unchanged and &lt;EM&gt;add&lt;/EM&gt; a new field based on the regex lookup. Is there any way of doing this?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2012 17:06:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-new-fields-using-rex-lookup/m-p/103444#M26736</guid>
      <dc:creator>monkey</dc:creator>
      <dc:date>2012-03-28T17:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new fields using rex lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-new-fields-using-rex-lookup/m-p/103445#M26737</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval fooX = foo | regex fooX="^10[0-9]{4}$(?&amp;lt;newfield&amp;gt;THINGTEN)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Just create a copy of the foo field first...&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2012 17:28:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-new-fields-using-rex-lookup/m-p/103445#M26737</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-03-28T17:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new fields using rex lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Creating-new-fields-using-rex-lookup/m-p/103446#M26738</link>
      <description>&lt;P&gt;Thanks! That will do the trick nicely! Simple and effective...&lt;/P&gt;</description>
      <pubDate>Wed, 28 Mar 2012 22:21:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Creating-new-fields-using-rex-lookup/m-p/103446#M26738</guid>
      <dc:creator>monkey</dc:creator>
      <dc:date>2012-03-28T22:21:20Z</dc:date>
    </item>
  </channel>
</rss>

