<?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: Getting nth line of a file in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147552#M185325</link>
    <description>&lt;P&gt;When you say "the input file can be splunked as well" does that mean you have control over how it is ingested?  If so, include the line number as a field with each line of input.  Then you can easily associate the log entry with the input line.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Apr 2014 18:52:22 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2014-04-30T18:52:22Z</dc:date>
    <item>
      <title>Getting nth line of a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147550#M185323</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;I'm trying to monitor the output of a batch job with splunk. The problem is that logging is poorly implemented and I need some sophisticated splunk (?) to meet my requirements.&lt;/P&gt;

&lt;P&gt;The job writes errors to a log file. Together with the error message it states the line of the input file where the error occured. The input file can be splunked as well.&lt;/P&gt;

&lt;P&gt;To be able to handle the error the guys in business department need the error message as well as the corresponding line in the input file.&lt;/P&gt;

&lt;P&gt;I can extract the message with the line number from the job's log file.&lt;/P&gt;

&lt;P&gt;How can I extract the correct line from the input file?&lt;/P&gt;

&lt;P&gt;So far I tried to parse each line of the input file as a different event and getting the nth one using streamstats. Unfortunately the result stream doesnt maintain the correct order of the lines.&lt;/P&gt;

&lt;P&gt;Any ideas about how I could extract the nth line of the file?&lt;/P&gt;

&lt;P&gt;Regards,&lt;/P&gt;

&lt;P&gt;Bernd&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2014 15:45:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147550#M185323</guid>
      <dc:creator>bleinfelder</dc:creator>
      <dc:date>2014-04-30T15:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nth line of a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147551#M185324</link>
      <description>&lt;P&gt;sample logs please.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2014 15:49:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147551#M185324</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-04-30T15:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nth line of a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147552#M185325</link>
      <description>&lt;P&gt;When you say "the input file can be splunked as well" does that mean you have control over how it is ingested?  If so, include the line number as a field with each line of input.  Then you can easily associate the log entry with the input line.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2014 18:52:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147552#M185325</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2014-04-30T18:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nth line of a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147553#M185326</link>
      <description>&lt;P&gt;You can select a specific line from an event like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=input_file
| eval lines = _raw | makemv tokenizer="(.+)" lines
| eval error_line = mvindex(lines, [stats count | eval line_number = 4 | return $line_number])
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm assuming your input file is indexed as one large event. The tokenizer turns the copy of &lt;CODE&gt;_raw&lt;/CODE&gt; into a multivalue field, with each entry corresponding to one line. &lt;CODE&gt;mvindex&lt;/CODE&gt; then accesses the line you need, as calculated by the subsearch that returns the line number from your error message.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2014 22:45:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147553#M185326</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-04-30T22:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Getting nth line of a file</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147554#M185327</link>
      <description>&lt;P&gt;thank you, this works perfect!&lt;/P&gt;</description>
      <pubDate>Wed, 07 May 2014 15:01:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Getting-nth-line-of-a-file/m-p/147554#M185327</guid>
      <dc:creator>bleinfelder</dc:creator>
      <dc:date>2014-05-07T15:01:56Z</dc:date>
    </item>
  </channel>
</rss>

