<?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: How to access a field name using variable ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303191#M166345</link>
    <description>&lt;P&gt;Without seeing your query or expected output, my suggestion would be this (the subsearch would return the current weekday value and pass it on to table command.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search giving fields for each weekday
| table [| gentimes start=-1 | eval search=strftime(now(),"%A") | table search ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 Aug 2017 14:32:53 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-08-28T14:32:53Z</dc:date>
    <item>
      <title>How to access a field name using variable ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303190#M166344</link>
      <description>&lt;P&gt;My Splunk results are returning multiple fields including fields  Sunday, Monday, Tuesday .... Saturday.&lt;/P&gt;

&lt;P&gt;Now my requirement is if today is Sunday i want to access the value of field name Sunday, if today is Monday i need to access the value of Monday and so on..&lt;/P&gt;

&lt;P&gt;Can someone help me in how to access the value of a field using variable ?  &lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 13:32:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303190#M166344</guid>
      <dc:creator>sagrl</dc:creator>
      <dc:date>2017-08-28T13:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to access a field name using variable ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303191#M166345</link>
      <description>&lt;P&gt;Without seeing your query or expected output, my suggestion would be this (the subsearch would return the current weekday value and pass it on to table command.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search giving fields for each weekday
| table [| gentimes start=-1 | eval search=strftime(now(),"%A") | table search ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Aug 2017 14:32:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303191#M166345</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-08-28T14:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to access a field name using variable ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303192#M166346</link>
      <description>&lt;P&gt;@sagrl, you can run a dummy search in your dashboard to get today's weekday as a token and then use the same in your other searches in the dashboard.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;| makeresults
| eval weekDay=lower(strftime(_time,"%A"))
    &amp;lt;/query&amp;gt;
    &amp;lt;progress&amp;gt;
       &amp;lt;set token="tokenWeekDay"&amp;gt;$result.weekDay$&amp;lt;/set&amp;gt;
    &amp;lt;/progress&amp;gt;
&amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then use the token &lt;CODE&gt;$tokenWeekDay$&lt;/CODE&gt; in your other searches in the dashboard:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;single&amp;gt;
    &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| makeresults
    | eval tokenData="$tokenWeekDay$"
    | table tokenData
        &amp;lt;/query&amp;gt;
    &amp;lt;/search&amp;gt;
&amp;lt;/single&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: I have changed the weekday to lower case using &lt;CODE&gt;lower()&lt;/CODE&gt; function. In case your use case is to match this against Splunk's default extracted field &lt;CODE&gt;date_wday, it should be lowercase. Result of strftime() time modifier&lt;/CODE&gt;%A&lt;CODE&gt;would result in Week Days like Sunday, Monday etc. As you have asked in your question. Hence, if you are search for same casing in weekday values, then you do not require lower() function, just&lt;/CODE&gt;strftime()` should work.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Aug 2017 14:35:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303192#M166346</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-28T14:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to access a field name using variable ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303193#M166347</link>
      <description>&lt;P&gt;I would do it like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval date_wday=strftime(now(), "%A")
| map [search index="YouShouldAlwaysSpecifyAnIndex" sourcetype="AndSourcetypeToo" MyFieldName="$date_wday$"]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Sep 2017 21:47:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-access-a-field-name-using-variable/m-p/303193#M166347</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-09-10T21:47:13Z</dc:date>
    </item>
  </channel>
</rss>

