<?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: Using a column of field names to dynamically select fields for use in eval expression in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365082#M107674</link>
    <description>&lt;P&gt;Try this new AddOn:  &lt;A href="https://splunkbase.splunk.com/app/4597/"&gt;https://splunkbase.splunk.com/app/4597/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;It does exactly what you are looking for.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;
| makeresults 
| eval Field1=1
| eval Field2=2
| eval Field3=3
| eval Field4=4
| eval pointer_field="Field4"
| pointerset newField pointer="pointer_field"
&lt;/PRE&gt;

&lt;PRE&gt;
Field1  Field2  Field3  Field4  pointer_field   newField    
1           2       3       4       Field4          4
&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Jul 2019 17:30:27 GMT</pubDate>
    <dc:creator>sbarr0</dc:creator>
    <dc:date>2019-07-19T17:30:27Z</dc:date>
    <item>
      <title>Using a column of field names to dynamically select fields for use in eval expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365076#M107668</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;

&lt;P&gt;Suppose my search generates the first 4 columns from the following table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;field1  field2  field3  lookup  result
x1      y1      z1      field1  x1
x2      y2      z2      field3  z2
x3      y3      z3      field2  y3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to create the &lt;EM&gt;result&lt;/EM&gt; column using values from &lt;EM&gt;lookup&lt;/EM&gt; to specify which &lt;EM&gt;fieldX&lt;/EM&gt; to extract the &lt;EM&gt;result&lt;/EM&gt; value from.&lt;/P&gt;

&lt;P&gt;So if I have an expression like  &lt;CODE&gt;...| eval result=lookup&lt;/CODE&gt;, what do I need to wrap around the &lt;CODE&gt;lookup&lt;/CODE&gt; to achieve the the &lt;EM&gt;result&lt;/EM&gt; column in the table above?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 12:17:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365076#M107668</guid>
      <dc:creator>dvanderlaan</dc:creator>
      <dc:date>2017-05-05T12:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using a column of field names to dynamically select fields for use in eval expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365077#M107669</link>
      <description>&lt;P&gt;Assuming you already have field1, field2, field3, and lookup, you should be able to get result with &lt;CODE&gt;case&lt;/CODE&gt;.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval result = case(lookup="field1", field1, lookup="field2",field2, lookup="field3",field3, 1=1,"oops")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2017 14:40:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365077#M107669</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-05-05T14:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using a column of field names to dynamically select fields for use in eval expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365078#M107670</link>
      <description>&lt;P&gt;Ideally I'm hoping for a solution which would scale well with large numbers of &lt;EM&gt;fieldX&lt;/EM&gt; columns. Sorry, I could have been more clear in the question.&lt;/P&gt;

&lt;P&gt;For example, &lt;CODE&gt;... | eval {lookup} = blargh&lt;/CODE&gt; uses values from one field to specify the name of another field. So I was hoping that something like &lt;CODE&gt;... | eval result = {lookup}&lt;/CODE&gt; might work, but doesn't.&lt;/P&gt;

&lt;P&gt;Is there anything like this in SPL?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 15:10:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365078#M107670</guid>
      <dc:creator>dvanderlaan</dc:creator>
      <dc:date>2017-05-05T15:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Using a column of field names to dynamically select fields for use in eval expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365079#M107671</link>
      <description>&lt;P&gt;Thanks a lot for your answer rich. It's certainly a solution to my question, but not quite what I was hoping for. I've added a comment to clarify what I'm looking for&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 15:10:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365079#M107671</guid>
      <dc:creator>dvanderlaan</dc:creator>
      <dc:date>2017-05-05T15:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using a column of field names to dynamically select fields for use in eval expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365080#M107672</link>
      <description>&lt;P&gt;It seems over complicated, but this should accomplish the need...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rename lookup to mylookup
 | appendpipe 
    [| map search="| makeresults | eval field1=$field1$ | eval field2=$field2$ | eval field3=$field3$ | eval result=$lookup$ | table field1 field2 field3 mylookup result" 
    | dedup field1 field2 field3 mylookup 
    | outputcsv mytemp.csv 
    | where false()
     ]
 | join type=left field1 field2 field3 mylookup [| inputcsv mytemp.csv ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2017 15:35:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365080#M107672</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-05T15:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using a column of field names to dynamically select fields for use in eval expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365081#M107673</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="x1 y1 z1 field1 x1::x2 y2 z2 field3 z2::x3 y3 z3 field2 y3" 
| makemv delim="::" raw 
| mvexpand raw 
| rex field=raw "(?&amp;lt;field1&amp;gt;\S+)\s+(?&amp;lt;field2&amp;gt;\S+)\s+(?&amp;lt;field3&amp;gt;\S+)\s+(?&amp;lt;lookup&amp;gt;\S+)\s+(?&amp;lt;expected_result&amp;gt;\S+)"
| fields - raw _time

| rename COMMENT AS "Everything above fakes sample data; everything below is your solution."

| eval result="N/A"
| foreach field* [eval result=if(lookup="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;", $&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;$, result)]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 May 2017 16:17:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365081#M107673</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-05-06T16:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using a column of field names to dynamically select fields for use in eval expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365082#M107674</link>
      <description>&lt;P&gt;Try this new AddOn:  &lt;A href="https://splunkbase.splunk.com/app/4597/"&gt;https://splunkbase.splunk.com/app/4597/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;It does exactly what you are looking for.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;
| makeresults 
| eval Field1=1
| eval Field2=2
| eval Field3=3
| eval Field4=4
| eval pointer_field="Field4"
| pointerset newField pointer="pointer_field"
&lt;/PRE&gt;

&lt;PRE&gt;
Field1  Field2  Field3  Field4  pointer_field   newField    
1           2       3       4       Field4          4
&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2019 17:30:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-a-column-of-field-names-to-dynamically-select-fields-for/m-p/365082#M107674</guid>
      <dc:creator>sbarr0</dc:creator>
      <dc:date>2019-07-19T17:30:27Z</dc:date>
    </item>
  </channel>
</rss>

