<?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 search if a string exists in a variable number of columns? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217029#M63735</link>
    <description>&lt;P&gt;If you just want the field names you could use something like this instead (not tested so play around with the quotes):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval fieldnames = ""
| foreach Id_* [eval fieldnames = if(match(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "xyz"), "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" . fieldnames, fieldnames)]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 19 Apr 2016 19:03:53 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-04-19T19:03:53Z</dc:date>
    <item>
      <title>How to search if a string exists in a variable number of columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217024#M63730</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;I have multiple columns (number of columns may vary) and wanted to search a string if it exists in any of the columns. How do I do this using a simple search?&lt;/P&gt;

&lt;P&gt;Log example: There are three statements&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Id_1="abc" Id_2="xyz"  Id_3="123"  Id_4="abcd"  Id_5="abc"  Id_6="abc"
Id_1="abc" Id_2="xyz"  Id_3="123"  
Id_1="abc" Id_2="123"  Id_3="123"  Id_4="abcd"  Id_5="abc"  Id_6="abc" Id_7="123"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've used the &lt;CODE&gt;table&lt;/CODE&gt; command like this: &lt;CODE&gt;| table Id_*&lt;/CODE&gt; to get a table of Id's&lt;BR /&gt;
OUTPUT for the above search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Id_1="abc" Id_2="xyz"  Id_3="123"  Id_4="abcd"  Id_5="abc"  Id_6="abc" Id_7="xyz"
Id_1="abc" Id_2="xyz"  Id_3="123"  Id_4=null         Id_5=null    Id_6=null    Id_7=null
Id_1="abc" Id_2="123"  Id_3="123"  Id_4="abcd"  Id_5="abc"  Id_6="abc" Id_7="123"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I wanted to search/get the records where Id_* is "xyz" . Can you help me with the search?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 17:41:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217024#M63730</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-04-19T17:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to search if a string exists in a variable number of columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217025#M63731</link>
      <description>&lt;P&gt;You could add "xyz" to you search. Like this &lt;CODE&gt;index=* "xyz" | table id_*&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 18:09:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217025#M63731</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-04-19T18:09:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to search if a string exists in a variable number of columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217026#M63732</link>
      <description>&lt;P&gt;Hi Sundareshr, Yeah , but the search string is also going to be in the other columns. I wanted to search only in the column Id_*&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 18:36:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217026#M63732</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-04-19T18:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to search if a string exists in a variable number of columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217027#M63733</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.. | table id_* | foreach ID_* [eval x=&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;."@@@"] | search x="xyz"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Apr 2016 18:51:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217027#M63733</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-04-19T18:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to search if a string exists in a variable number of columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217028#M63734</link>
      <description>&lt;P&gt;Can you explain the query please? I'm seeing this error&lt;/P&gt;

&lt;P&gt;Failed to parse templatized search for field 'Id_1'&lt;BR /&gt;
Failed to parse templatized search for field 'Id_2'&lt;BR /&gt;
Failed to parse templatized search for field 'Id_3'&lt;BR /&gt;
Failed to parse templatized search for field 'Id_4' &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:30:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217028#M63734</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2020-09-29T09:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to search if a string exists in a variable number of columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217029#M63735</link>
      <description>&lt;P&gt;If you just want the field names you could use something like this instead (not tested so play around with the quotes):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval fieldnames = ""
| foreach Id_* [eval fieldnames = if(match(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "xyz"), "&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;" . fieldnames, fieldnames)]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Apr 2016 19:03:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217029#M63735</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-04-19T19:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to search if a string exists in a variable number of columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217030#M63736</link>
      <description>&lt;P&gt;Perfect , This worked. It created a new column - "fieldnames" with the original column name. I could just search the new column which has no nulls.&lt;/P&gt;

&lt;P&gt;Thanks for your time Javiergn.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2016 19:59:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-if-a-string-exists-in-a-variable-number-of-columns/m-p/217030#M63736</guid>
      <dc:creator>Kukkadapu</dc:creator>
      <dc:date>2016-04-19T19:59:01Z</dc:date>
    </item>
  </channel>
</rss>

