<?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 Combine Multiple Fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combine-Multiple-Fields/m-p/538662#M152299</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm relatively new to Splunk. I have multiple fields with different naming schemes that have different&amp;nbsp; or identical values. Here's an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;hash=yj843yj387hfhjf723hjf47hnf29nf&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;hashes=xmv98svmd89djmfv98jvkfj9jm&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Hashes=n9nuevur9vv9v8fj0fefjeffjv9ejve8&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;sha1_hash=84hmrh42mfu2hmxufxfmu28&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;src_hash=2xf9mf4jmfijjumrfx2r9mjfru2mjrm9j&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;name=jayson&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Src_name=jayson&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;NAME=jayson&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;SubjectUserName=jayson&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to make a query checks if there is a field that contains the word "hash" or "name" and tables it out. Here's what I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;| eval Hash=hash, Hash=hashes&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;| foreach Hash* [eval Hash=mvappend(Hash, "")]&lt;BR /&gt;| eval Name=name, Name=Src_name&lt;BR /&gt;| foreach Name* [eval Name=mvappend(Name, "")&lt;BR /&gt;| table Name Hash&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I need to table the results from any field that has the word "hash" or "name" in it. Also is there a way to simplify this?&lt;/P&gt;</description>
    <pubDate>Thu, 04 Feb 2021 18:15:40 GMT</pubDate>
    <dc:creator>JaysonD123</dc:creator>
    <dc:date>2021-02-04T18:15:40Z</dc:date>
    <item>
      <title>Combine Multiple Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-Multiple-Fields/m-p/538662#M152299</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm relatively new to Splunk. I have multiple fields with different naming schemes that have different&amp;nbsp; or identical values. Here's an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;hash=yj843yj387hfhjf723hjf47hnf29nf&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;hashes=xmv98svmd89djmfv98jvkfj9jm&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Hashes=n9nuevur9vv9v8fj0fefjeffjv9ejve8&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;sha1_hash=84hmrh42mfu2hmxufxfmu28&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;src_hash=2xf9mf4jmfijjumrfx2r9mjfru2mjrm9j&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;name=jayson&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Src_name=jayson&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;NAME=jayson&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;SubjectUserName=jayson&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to make a query checks if there is a field that contains the word "hash" or "name" and tables it out. Here's what I have so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;| eval Hash=hash, Hash=hashes&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;| foreach Hash* [eval Hash=mvappend(Hash, "")]&lt;BR /&gt;| eval Name=name, Name=Src_name&lt;BR /&gt;| foreach Name* [eval Name=mvappend(Name, "")&lt;BR /&gt;| table Name Hash&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;I need to table the results from any field that has the word "hash" or "name" in it. Also is there a way to simplify this?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 18:15:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-Multiple-Fields/m-p/538662#M152299</guid>
      <dc:creator>JaysonD123</dc:creator>
      <dc:date>2021-02-04T18:15:40Z</dc:date>
    </item>
    <item>
      <title>Re: Combine Multiple Fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combine-Multiple-Fields/m-p/538685#M152306</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231217"&gt;@JaysonD123&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good to see that you're diving in the deep end with the use of foreach, which is not such a commonly used command, but a very powerful one...&lt;/P&gt;&lt;P&gt;You're on the right track, but your initial assignments Hash=hash, Hash=hashes, will not do much good as it's making the field Hash equal to the field hashes, regardless of what hash is.&lt;/P&gt;&lt;P&gt;Fields are case sensitive, so from your sample data, you need to be doing a case insensitive comparison of the field name to either name or hashes. This runnable example shows you how to do this, also using foreach, but using the &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; and &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; elements of foreach, which are crucial to getting this to work.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval hash="yj843yj387hfhjf723hjf47hnf29nf"
| eval hashes="xmv98svmd89djmfv98jvkfj9jm"
| eval Hashes="n9nuevur9vv9v8fj0fefjeffjv9ejve8"
| eval sha1_hash="84hmrh42mfu2hmxufxfmu28"
| eval src_hash="2xf9mf4jmfijjumrfx2r9mjfru2mjrm9j"
| eval name="jayson"
| eval Src_name="jayson"
| eval NAME="jayson"
| eval SubjectUserName="jayson"
| eval anotherField1="Something else", anotherField2="another"
| foreach * [ eval N=if(match("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;","(?i)name"), mvappend("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=".&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, N), N),  H=if(match("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;","(?i)hash"), mvappend("&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=".&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, H), H)]&lt;/LI-CODE&gt;&lt;P&gt;All you need is the&amp;nbsp; foreach statement. I have made it foreach *, so all field names can be checked. The H and N fields end up with a multi value field with fieldName=value for each of the matching fields.&lt;/P&gt;&lt;P&gt;Edit the mvappend as required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 21:11:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combine-Multiple-Fields/m-p/538685#M152306</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-02-04T21:11:31Z</dc:date>
    </item>
  </channel>
</rss>

