<?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: Read a field value which field name is in another field. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/579109#M201813</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/30092"&gt;@mseijos&lt;/a&gt;, I stumbled accross the same problem and think I got a solution, based on previous contribs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;| makeresults count=10 
| fields - _time 
| streamstats count 
| eval dummyName1="dummyVal1",dummyName2="dummyVal2", name="count", dummyName3="dummyVal3",dummyName4="dummyVal4" 
| foreach * 
    [| eval fieldnames=mvappend(fieldnames,"&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;")
    | eval fieldvalues=mvappend(fieldvalues,&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)
    | eval value=mvindex(fieldvalues,mvfind(fieldnames,name)) 
    ]
| fields - dummy* fieldnames fieldvalues 
| table count name value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added dummy values to test the code, as simpler solutions weren't working with a lot of fields per log (because foreach parses all values)&lt;/P&gt;&lt;P&gt;I know it's surely too late for you, but maybe some others will find this interesting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Dec 2021 14:54:06 GMT</pubDate>
    <dc:creator>HappySplunker</dc:creator>
    <dc:date>2021-12-22T14:54:06Z</dc:date>
    <item>
      <title>How to read a field value which field name is in another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/494681#M137881</link>
      <description>&lt;P&gt;We have this table:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/8015iEADB7975AFB7FA28/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And we want to have a field (for example, named "value") that gets the value of the field which name is in the "name" field.&lt;BR /&gt;In the first row it would be value=3d, in the second row value would be value=1&lt;/P&gt;
&lt;P&gt;Its similar to what &lt;BR /&gt;| eval {name} = "whatever"&lt;/P&gt;
&lt;P&gt;would do, but reading instead of writing.&lt;BR /&gt;(something like | eval value = {name} but that doesn't work).&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 22:32:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/494681#M137881</guid>
      <dc:creator>mseijos</dc:creator>
      <dc:date>2022-06-30T22:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Read a field value which field name is in another field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/494682#M137882</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | foreach name [ eval value="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Nov 2019 03:27:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/494682#M137882</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-11-29T03:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Read a field value which field name is in another field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/494683#M137883</link>
      <description>&lt;P&gt;I tried your solution with this code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval a="1"
| eval b="2"
| eval name="a"
| foreach name [ eval value="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But "value" field gets the literal "name" as value. If I remove the quotes in &lt;CODE&gt;&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;&lt;/CODE&gt;, I get the literal "a" in "value" field. &lt;BR /&gt;
The expected "value" field would be "1"&lt;/P&gt;</description>
      <pubDate>Fri, 29 Nov 2019 08:09:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/494683#M137883</guid>
      <dc:creator>mseijos</dc:creator>
      <dc:date>2019-11-29T08:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: Read a field value which field name is in another field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/522092#M147206</link>
      <description>&lt;P&gt;I needed something like this also.&lt;/P&gt;&lt;P&gt;How about this inefficient solution?&amp;nbsp; It seems to work as long as you get the right fields into the `foreach` part...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=10 | streamstats count
| eval a="1", b="2", name="count"
| foreach * [ eval value=mvindex(mvappend(case(name="&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;",'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),value),0) ]&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:01:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/522092#M147206</guid>
      <dc:creator>kulick</dc:creator>
      <dc:date>2020-09-29T20:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Read a field value which field name is in another field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/522129#M147215</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval fieldnames="fieldnames"
| eval fieldvalues="dummy"
| foreach * [| eval fieldnames=if(match("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;","fieldnames|fieldvalues"),fieldnames,mvappend(fieldnames,"&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;")) | eval fieldvalues=if(match("&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;","fieldnames|fieldvalues"),fieldvalues,mvappend(fieldvalues,&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;))]
| eval value=mvindex(fieldvalues,mvfind(fieldnames,name))
| fields - fieldnames fieldvalues&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 06:56:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/522129#M147215</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2020-09-30T06:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Read a field value which field name is in another field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/579109#M201813</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/30092"&gt;@mseijos&lt;/a&gt;, I stumbled accross the same problem and think I got a solution, based on previous contribs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;| makeresults count=10 
| fields - _time 
| streamstats count 
| eval dummyName1="dummyVal1",dummyName2="dummyVal2", name="count", dummyName3="dummyVal3",dummyName4="dummyVal4" 
| foreach * 
    [| eval fieldnames=mvappend(fieldnames,"&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;")
    | eval fieldvalues=mvappend(fieldvalues,&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)
    | eval value=mvindex(fieldvalues,mvfind(fieldnames,name)) 
    ]
| fields - dummy* fieldnames fieldvalues 
| table count name value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I added dummy values to test the code, as simpler solutions weren't working with a lot of fields per log (because foreach parses all values)&lt;/P&gt;&lt;P&gt;I know it's surely too late for you, but maybe some others will find this interesting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 14:54:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/579109#M201813</guid>
      <dc:creator>HappySplunker</dc:creator>
      <dc:date>2021-12-22T14:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Read a field value which field name is in another field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/604047#M210130</link>
      <description>&lt;P&gt;@&lt;SPAN class=""&gt;&lt;A class="" href="https://community.splunk.com/t5/user/viewprofilepage/user-id/241680" target="_self"&gt;&lt;SPAN class=""&gt;HappySplunker&amp;nbsp;&lt;/SPAN&gt;&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Your solution simplifies OP's requirements. You made an assumption that&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;name="count"&lt;/PRE&gt;&lt;P&gt;for &lt;STRONG&gt;every&lt;/STRONG&gt; event.&lt;BR /&gt;&lt;BR /&gt;This is not the case.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 21:28:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/604047#M210130</guid>
      <dc:creator>pm771</dc:creator>
      <dc:date>2022-06-30T21:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Read a field value which field name is in another field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/614266#M213449</link>
      <description>&lt;P&gt;Here's an updated version to be as close as possible to &lt;SPAN&gt;OP's requirements&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults count=4 
| streamstats count 
| eval age = case(count=1, 12, count=2, 25, count=3, 65, count=4, 21) 
| eval city = case(count=1, "Paris", count=2, "Berlin",count=3, "Tokyo", count=4, "Madrid") 
| eval name = case(count=1, "age", count=2, null(),count=3, "city", count=4, null()) 
| fields - _time count 
| foreach * 
    [| eval fieldnames=mvappend(fieldnames,"&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;") 
    | eval fieldvalues=mvappend(fieldvalues,&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;) 
    | eval value=mvindex(fieldvalues,mvfind(fieldnames,name)) 
        ] 
| fields -  fieldnames fieldvalues&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HappySplunker_0-1663920657439.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/21638iF27CB569DF177D3A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HappySplunker_0-1663920657439.png" alt="HappySplunker_0-1663920657439.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 08:11:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/614266#M213449</guid>
      <dc:creator>HappySplunker</dc:creator>
      <dc:date>2022-09-23T08:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Read a field value which field name is in another field.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/660972#M228202</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/30092"&gt;@mseijos&lt;/a&gt;&amp;nbsp;- Marking this answer as accepted as it seems working. And it has been answered correctly first. Let me know if this doesn't work for you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Splunk Community Moderator,&lt;/P&gt;&lt;P&gt;Vatsal Jagani&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 07:12:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-read-a-field-value-which-field-name-is-in-another-field/m-p/660972#M228202</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2023-10-17T07:12:45Z</dc:date>
    </item>
  </channel>
</rss>

