<?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: removing last two characters from results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83838#M21362</link>
    <description>&lt;P&gt;The easiest way is probably to use the &lt;CODE&gt;substr&lt;/CODE&gt; function within &lt;CODE&gt;eval&lt;/CODE&gt;.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=webproxy | regex user=".+a" | top 100 user | eval user_name=substr(user,1,5) ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE&lt;/P&gt;

&lt;P&gt;Assuming your user lookup table is defined in &lt;CODE&gt;transforms.conf&lt;/CODE&gt; as &lt;CODE&gt;user_list&lt;/CODE&gt;.  This should let you pull data from it into your current search data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=webproxy | regex user=".+a" | top 100 user | eval user_name=substr(user,1,5)
| lookup user_list 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your &lt;CODE&gt;transforms.conf&lt;/CODE&gt; stanza for user_list might look as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[user_list]
filename=userlist.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some relevant documentation is available at &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Lookup"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Lookup&lt;/A&gt; and &lt;A href="http://docs.splunk.com/Documentation/Splunk/4.2.3/Knowledge/Addfieldsfromexternaldatasources"&gt;http://docs.splunk.com/Documentation/Splunk/4.2.3/Knowledge/Addfieldsfromexternaldatasources&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Sep 2011 04:27:55 GMT</pubDate>
    <dc:creator>dwaddle</dc:creator>
    <dc:date>2011-09-30T04:27:55Z</dc:date>
    <item>
      <title>removing last two characters from results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83837#M21361</link>
      <description>&lt;P&gt;My search looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=webproxy | regex user=".+a" | top 100 user 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;results are &lt;CODE&gt;j9999la&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I want to list the real result, but also remove anything after the first 5 character and display this also.&lt;/P&gt;

&lt;P&gt;The result &lt;CODE&gt;j9999&lt;/CODE&gt; can be used in a lookup to give me a person's name.&lt;/P&gt;

&lt;P&gt;So what I really want to see is&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;user               user_name               real_name
j9999la            j9999                   John Doe
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I get the everything after the 5th character removed - I can handle the rest          &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE&lt;/P&gt;

&lt;P&gt;This does exactly what I want it to do, but I thought I would be able to figure out the second part - not really...&lt;/P&gt;

&lt;P&gt;So, the results of user_name relate to a person. If the results of the user_name were part of the original data and it was called user - I would have additional fields returned with information on the user, such as full name, location, phone, etc.&lt;/P&gt;

&lt;P&gt;We query an employee database twice a day to populate a csv containing all the employees.&lt;/P&gt;

&lt;P&gt;How can I pass my results of user_name to the csv to populate the employee data?&lt;/P&gt;

&lt;P&gt;BTW - not sure how we do this, but I do not pass anything to the csv now - it is just part of my data. This was setup by professional services.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:56:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83837#M21361</guid>
      <dc:creator>mcbradford</dc:creator>
      <dc:date>2020-09-28T09:56:00Z</dc:date>
    </item>
    <item>
      <title>Re: removing last two characters from results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83838#M21362</link>
      <description>&lt;P&gt;The easiest way is probably to use the &lt;CODE&gt;substr&lt;/CODE&gt; function within &lt;CODE&gt;eval&lt;/CODE&gt;.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=webproxy | regex user=".+a" | top 100 user | eval user_name=substr(user,1,5) ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE&lt;/P&gt;

&lt;P&gt;Assuming your user lookup table is defined in &lt;CODE&gt;transforms.conf&lt;/CODE&gt; as &lt;CODE&gt;user_list&lt;/CODE&gt;.  This should let you pull data from it into your current search data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=webproxy | regex user=".+a" | top 100 user | eval user_name=substr(user,1,5)
| lookup user_list 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your &lt;CODE&gt;transforms.conf&lt;/CODE&gt; stanza for user_list might look as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[user_list]
filename=userlist.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Some relevant documentation is available at &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Lookup"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Lookup&lt;/A&gt; and &lt;A href="http://docs.splunk.com/Documentation/Splunk/4.2.3/Knowledge/Addfieldsfromexternaldatasources"&gt;http://docs.splunk.com/Documentation/Splunk/4.2.3/Knowledge/Addfieldsfromexternaldatasources&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2011 04:27:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83838#M21362</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2011-09-30T04:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: removing last two characters from results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83839#M21363</link>
      <description>&lt;P&gt;Have you taken a look at the following search commands:&lt;/P&gt;

&lt;P&gt;outputlookup&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Outputlookup"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Outputlookup&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;outputcsv &lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Outputcsv"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Outputcsv&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2011 15:44:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83839#M21363</guid>
      <dc:creator>tgow</dc:creator>
      <dc:date>2011-09-30T15:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: removing last two characters from results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83840#M21364</link>
      <description>&lt;P&gt;mcbradford,  I took your answer below and merged it into the original question as an update.  The answers system lets you edit your original question/answer as necessary.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Sep 2011 18:13:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/removing-last-two-characters-from-results/m-p/83840#M21364</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2011-09-30T18:13:00Z</dc:date>
    </item>
  </channel>
</rss>

