<?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 Create and De-reference New Field Names in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671306#M230064</link>
    <description>&lt;P&gt;I have Linux audit records that have a field called type and fields with the naming convention lower(type).field.&amp;nbsp; I want to be able to combine type, as a prefix, and a set of suffixes to create new field names that exist in the data.&amp;nbsp; For example, I have a type called FILE_WATCH and fields called file_watch.exe, file_watch.egid, file_watch.comm, etc.&lt;/P&gt;&lt;P&gt;I want to develop a dashboard table by type and suffix in Splunk to show if a particular field exists for a type.&amp;nbsp; So going back to my example using type=FILE_WATCH, how can I create a new field name along these lines?&lt;/P&gt;&lt;P&gt;base = lower(type)&lt;BR /&gt;exe={base}.".exe"&amp;nbsp; # does not work, but you get the idea.&lt;/P&gt;&lt;P&gt;with exe now equal to the field name, I want to be able to de-reference the new field name to see if it exists.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Dec 2023 18:59:23 GMT</pubDate>
    <dc:creator>tom_porter</dc:creator>
    <dc:date>2023-12-08T18:59:23Z</dc:date>
    <item>
      <title>Create and De-reference New Field Names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671306#M230064</link>
      <description>&lt;P&gt;I have Linux audit records that have a field called type and fields with the naming convention lower(type).field.&amp;nbsp; I want to be able to combine type, as a prefix, and a set of suffixes to create new field names that exist in the data.&amp;nbsp; For example, I have a type called FILE_WATCH and fields called file_watch.exe, file_watch.egid, file_watch.comm, etc.&lt;/P&gt;&lt;P&gt;I want to develop a dashboard table by type and suffix in Splunk to show if a particular field exists for a type.&amp;nbsp; So going back to my example using type=FILE_WATCH, how can I create a new field name along these lines?&lt;/P&gt;&lt;P&gt;base = lower(type)&lt;BR /&gt;exe={base}.".exe"&amp;nbsp; # does not work, but you get the idea.&lt;/P&gt;&lt;P&gt;with exe now equal to the field name, I want to be able to de-reference the new field name to see if it exists.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 18:59:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671306#M230064</guid>
      <dc:creator>tom_porter</dc:creator>
      <dc:date>2023-12-08T18:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create and De-reference New Field Names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671309#M230065</link>
      <description>&lt;P&gt;I'm not sure if I get the idea. &amp;nbsp;Do you mean to use this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;base = lower(type)
exe=base.".exe" &lt;/LI-CODE&gt;&lt;P&gt;What is the intention of the curly brackets? (No, {base} is not a valid expression.)&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 19:34:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671309#M230065</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-12-08T19:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create and De-reference New Field Names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671313#M230069</link>
      <description>&lt;P&gt;Curly braces on the LHS of an eval says to use the contents of the field as the new field name.&lt;/P&gt;&lt;P&gt;See if this example query helps explain&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval base="file_watch"
| eval {base}= base.".exe"
| eval {base}exe=base.".exe"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 20:16:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671313#M230069</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-12-08T20:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create and De-reference New Field Names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671317#M230071</link>
      <description>&lt;P&gt;I stand corrected. &amp;nbsp;Thanks,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;Now,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/259005"&gt;@tom_porter&lt;/a&gt;&amp;nbsp;will need to explain what "does not work" means. &amp;nbsp;To be clear, this phrase should be forbidden in a forum like this as it conveys very little information in the best scenarios.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Illustrate/mock your data (anonymize as needed),&lt;/LI&gt;&lt;LI&gt;show code you tried,&lt;/LI&gt;&lt;LI&gt;show actual results (anonymize as needed),&lt;/LI&gt;&lt;LI&gt;illustrate/mock desired results,&lt;/LI&gt;&lt;LI&gt;explain the logic connecting data and desired results if it is not painfully obvious.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Also explain the difference between actual results and desired results if it is not painfully obvious.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 21:53:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671317#M230071</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-12-08T21:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create and De-reference New Field Names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671553#M230128</link>
      <description>&lt;P&gt;I was trying something along the lines of &lt;A title="Dynamic Field Creation" href="https://docs.splunk.com/Documentation/Splunk/9.1.2/SearchReference/Eval" target="_blank" rel="noopener"&gt;dynamic field creation&lt;/A&gt;.&amp;nbsp; At issue is that we have multiple dot notation field names with different prefixes, but a common suffix.&amp;nbsp; (e.g.: file_watch.sgid and execve.sgid).&amp;nbsp;&amp;nbsp;&amp;nbsp; There are about 40 prefixes and 50 or more suffixes.&amp;nbsp; Not all prefixes have all suffixes.&amp;nbsp; What I wanted to do was to create a dashboard that would show the prefixes as rows, and the suffixes as columns, with x marking cells with non-null values for prefix.suffix based on a search over the last 24 hours.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 12:15:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671553#M230128</guid>
      <dc:creator>tom_porter</dc:creator>
      <dc:date>2023-12-12T12:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create and De-reference New Field Names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671651#M230139</link>
      <description>&lt;P&gt;Not sure if I am interpreting your question correctly but I gave it a shot.&lt;BR /&gt;&lt;BR /&gt;So given that the are many different fieldnames with dot notation.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1702425925462.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28469i6A8B7EFD3D361CAD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1702425925462.png" alt="dtburrows3_0-1702425925462.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You are trying to get a final table of something like this?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_1-1702425976363.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28470i1317029B01A78DF4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_1-1702425976363.png" alt="dtburrows3_1-1702425976363.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I was able to achieve this by utilizing a foreach loop&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
    | eval
        "tmp.exe"="value1"
    | append
        [
            | makeresults
                | eval
                    "noop.spl"="value2"
            ]
    | append
        [
            | makeresults
                | eval
                    "tmp.spl"="value3"
            ]
    | append
        [
            | makeresults
                | eval
                    "foo.exe"="value4"
            ]
    | append
        [
            | makeresults
                | eval
                    "tmp.tgz"="value5"
            ]
    | append
        [
            | makeresults
                | eval
                    "foo.tgz"="value6",
                    "tmp.exe"="value7"
            ]
    
    ``` Gather unique fieldnames as values of a new field ```
    | foreach *.*
        [
            | eval
                existing_fieldname=if(
                    isnotnull('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'),
                        mvappend(
                            'existing_fieldname',
                            "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"
                            ),
                        'existing_fieldname'
                    )
                    
            ]
    ``` Parse out prefix and suffix of the new field ```
    | eval
        prefix=case(
            isnull(existing_fieldname), null(),
            mvcount(existing_fieldname)==1, mvindex(split(existing_fieldname, "."), 0),
            mvcount(existing_fieldname)&amp;gt;1, mvmap(existing_fieldname, mvindex(split(existing_fieldname, "."), 0))
            ),
        suffix=case(
            isnull(existing_fieldname), null(),
            mvcount(existing_fieldname)==1, mvindex(split(existing_fieldname, "."), 1),
            mvcount(existing_fieldname)&amp;gt;1, mvmap(existing_fieldname, mvindex(split(existing_fieldname, "."), 1))
            )
    ``` Use chart function to display unique combos of prefix/suffix from inherited fieldnames ```
    | chart limit=50
        count as count
            over prefix
            by suffix
    ``` Replace numbers in the table with "X" to signify that the prefix/suffix combo was found in the data ```
    | foreach *
        [
            | eval
                &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if(
                    NOT "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"=="prefix",
                        if(
                            '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'&amp;gt;0,
                                "X",
                                null()
                            ),
                        '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'
                    )
            ]&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 13 Dec 2023 00:09:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671651#M230139</guid>
      <dc:creator>dtburrows3</dc:creator>
      <dc:date>2023-12-13T00:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create and De-reference New Field Names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671787#M230175</link>
      <description>&lt;P&gt;Yes!!!&amp;nbsp; That second table.&amp;nbsp;&amp;nbsp; Thank you....will try out your solution later this week.&amp;nbsp; Much appreciation to you all for chiming in on this.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 18:59:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/671787#M230175</guid>
      <dc:creator>tom_porter</dc:creator>
      <dc:date>2023-12-13T18:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create and De-reference New Field Names</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/673435#M230604</link>
      <description>&lt;P&gt;Jumping in on an aging topic, but you may be able to simplify the SPL, albeit with an unknown impact to performance. (Always test!)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;| makeresults format=json data="[{\"foo\": {\"field1\": \"value1\", \"field2\": \"value2\"}}, {\"bar\": {\"field1\": \"value3\", \"field2\": \"value4\"}}, {\"baz\": {\"field2\": \"value5\", \"field3\": \"value6\"}}]"
| spath
``` end test data ```
| table *.*
| transpose
| rex field=column "(?&amp;lt;prefix&amp;gt;[^.]+)\\.(?&amp;lt;suffix&amp;gt;.+)"
| foreach row* [ eval value=coalesce('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;', value) ]
| xyseries prefix suffix value&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 06 Jan 2024 17:35:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-and-De-reference-New-Field-Names/m-p/673435#M230604</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2024-01-06T17:35:36Z</dc:date>
    </item>
  </channel>
</rss>

