<?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: Can I populate a macro from search results? in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292958#M2581</link>
    <description>&lt;P&gt;HI&lt;/P&gt;

&lt;P&gt;You can try it with return command.&lt;BR /&gt;
like..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="A" [ search SECOND_SEARCH | return MACHINE]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;SECOND_SEARCH is the logic which you want to pass in macro.&lt;/P&gt;

&lt;P&gt;Please see return doc for more info.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Return"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Return&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Nov 2017 08:12:48 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2017-11-22T08:12:48Z</dc:date>
    <item>
      <title>Can I populate a macro from search results?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292956#M2579</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to take the results of a search that returns 1000 machines and search for them in an index. Not sure what the best way to accomplish this is...&lt;/P&gt;

&lt;P&gt;I was attempting to create tokens with 100 machines in each (MACHINE="A" OR MACHINE="B" OR MACHINE="C") and put them in a macro - $token1$ $token2$ $token3$ ... etc. which would result in 1000 machines listed in the format above to search against an index - index="A" (&lt;CODE&gt;macro&lt;/CODE&gt;). Is there a better way to create a list from a search and drop it into a macro? Right now the limitation I am running into is the amount of characters in a eval field.&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 05:28:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292956#M2579</guid>
      <dc:creator>poxx82</dc:creator>
      <dc:date>2017-11-22T05:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Can I populate a macro from search results?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292957#M2580</link>
      <description>&lt;P&gt;Macros are not for this purpose. If I understood the requirement correctly you want to search for list of host from one query and then use this list  in another query. Good option would be to use JOIN query or append query.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 07:00:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292957#M2580</guid>
      <dc:creator>hardikJsheth</dc:creator>
      <dc:date>2017-11-22T07:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can I populate a macro from search results?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292958#M2581</link>
      <description>&lt;P&gt;HI&lt;/P&gt;

&lt;P&gt;You can try it with return command.&lt;BR /&gt;
like..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="A" [ search SECOND_SEARCH | return MACHINE]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;SECOND_SEARCH is the logic which you want to pass in macro.&lt;/P&gt;

&lt;P&gt;Please see return doc for more info.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Return"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Return&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 08:12:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292958#M2581</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-22T08:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Can I populate a macro from search results?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292959#M2582</link>
      <description>&lt;P&gt;In short, NO.  &lt;/P&gt;

&lt;P&gt;Macros are evaluated first, before any searching happens.&lt;/P&gt;

&lt;P&gt;However, what you are asking for is pretty easy, with at least three different ways you can do it.&lt;/P&gt;

&lt;P&gt;First, use a subsearch.&lt;/P&gt;

&lt;P&gt;1) Create a search that gets you 1000 MACHINES (only that one field, in a table).&lt;BR /&gt;
2) Put it in brackets&lt;BR /&gt;
3) The system will execute the subsearch, return a value that looks like &lt;CODE&gt;( ( MACHINE="machine1" )  OR ( MACHINE="machine2" ) OR... )&lt;/CODE&gt;&lt;BR /&gt;
4) you're done.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo  [ your search that gets 1000 records | table MACHINE ] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;SECOND METHOD - &lt;/P&gt;

&lt;P&gt;1) Create a first search that saves the 1000 values for MACHINE to a lookup table&lt;BR /&gt;
2) create a second search that uses &lt;CODE&gt;| lookup mytable MACHINE OUTPUT MACHINE as foundme | where isnotnull(foundme)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;THere are lots more.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 04:22:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292959#M2582</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-11-25T04:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Can I populate a macro from search results?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292960#M2583</link>
      <description>&lt;P&gt;What you are really looking for is a subsearch.  Here is a search that generates a list of 100 like you indicated:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval MACHINE=mvrange(1,101)
| rex field=MACHINE mode=sed "s/^/MACHINE/"
| format
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Really, though, I would read this list from a lookup and then it would be like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup YourLookupWithListOfMachinesHere
| format
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You could bury this inside of a macro but I really don't see the point.  To use one, put it inside of square-brackets to define a subsearch in your main search like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo [| inputlookup YourLookupWithListOfMachinesHere]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Nov 2017 21:08:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Can-I-populate-a-macro-from-search-results/m-p/292960#M2583</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-11-25T21:08:42Z</dc:date>
    </item>
  </channel>
</rss>

