<?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 How to number each line in a multiline event? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135019#M27779</link>
    <description>&lt;P&gt;Is there a way to take a multiline event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;a 1 b 2
c 2 d 4
e 5 c 6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and number each line?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1 a 1 b 2
2 c 2 d 4
3 e 5 c 6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;like this?&lt;/P&gt;

&lt;P&gt;Maybe using streamstats and current=f?&lt;/P&gt;</description>
    <pubDate>Tue, 14 Apr 2015 14:43:44 GMT</pubDate>
    <dc:creator>landen99</dc:creator>
    <dc:date>2015-04-14T14:43:44Z</dc:date>
    <item>
      <title>How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135019#M27779</link>
      <description>&lt;P&gt;Is there a way to take a multiline event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;a 1 b 2
c 2 d 4
e 5 c 6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and number each line?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1 a 1 b 2
2 c 2 d 4
3 e 5 c 6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;like this?&lt;/P&gt;

&lt;P&gt;Maybe using streamstats and current=f?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2015 14:43:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135019#M27779</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-04-14T14:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135020#M27780</link>
      <description>&lt;P&gt;Streamstats should work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your_search&amp;gt; | streamstats count as EVTCOUNT 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Each event then should have EVTCOUNT, one per event, increasing.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2015 19:47:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135020#M27780</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2015-04-14T19:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135021#M27781</link>
      <description>&lt;P&gt;I am talking about numbering the lines of multiline events  You solution provides number of events and not the lines in each event, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  a 1 b 2
1 c 2 d 4
  e 5 c 6
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2015 12:09:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135021#M27781</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-04-15T12:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135022#M27782</link>
      <description>&lt;P&gt;try like this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats sum(linecount) as rank
or
| streamstats sum(linecount) as rank| table   rank|
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2015 12:52:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135022#M27782</guid>
      <dc:creator>fdi01</dc:creator>
      <dc:date>2015-04-15T12:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135023#M27783</link>
      <description>&lt;P&gt;The linecount of the first event is 3, so I believe that would yield:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  a 1 b 2
3 c 2 d 4
  e 5 c 6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the next event were exactly the same and had therefore had 3 lines, we should see:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  a 1 b 2
6 c 2 d 4
  e 5 c 6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I will test later to verify.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2015 14:36:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135023#M27783</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-04-15T14:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135024#M27784</link>
      <description>&lt;P&gt;Hi landen99&lt;BR /&gt;
Try the search code below&lt;BR /&gt;
examine attentively After extracting the fields which are in your event&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   .....|rex max_match=0 field=_raw "\s+(?P&amp;lt;field1&amp;gt;\S+)\s+(?P&amp;lt;field2&amp;gt;\d+)\s+(?P&amp;lt;field3&amp;gt;\S+)\s+(?P&amp;lt;field4&amp;gt;\d+)"| eval fields=mvzip(field1,mvzip(field2,mvzip(field3,field4)))|mvexpand fields|eval fil=split(fields,",")|eval fiel1=mvindex(fil,0)|eval fiel2=mvindex(fil,1)|eval fiel3=mvindex(fil,2)
        |eval fiel4=mvindex(fil,3)|streamstats count as number_line|eval fi1=mvzip(number_line,mvzip(fiel1,mvzip(fiel2,mvzip(fiel3,fiel4," ")," ")," ")," ")|stats list(fi1) as test2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2015 15:03:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135024#M27784</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2015-04-15T15:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135025#M27785</link>
      <description>&lt;P&gt;This search appears to do the following:&lt;BR /&gt;
 * extract each column as field1-4 (using rex)&lt;BR /&gt;
 * combine each field into line field called fields  (using mvzip)&lt;BR /&gt;
 * separates the multivalue field of lines into separate events&lt;BR /&gt;
 * splits the line field by commas which do not exist in the value ...&lt;/P&gt;

&lt;P&gt;It would be so much easier to just separate the  event by lines into new events and then streamstats count to track event and line order separately&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| streamstats count AS event_num | rex max_match=0 "(?P&amp;lt;line&amp;gt;[^\n]+)\n+" | mvexpand line | streamstats count AS line_num by event_num | eval line_new=line_num." - ".line | stats list(line_new) AS line_new by event_num
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Apr 2015 17:46:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135025#M27785</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-04-15T17:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135026#M27786</link>
      <description>&lt;P&gt;You should try the &lt;CODE&gt;accum&lt;/CODE&gt; command in the search language. This will allow you to aggregate to a variable value in an ascending fashion. For instance, assume that your data has been indexed. &lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/304iBCFCDBC1B164B12C/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Because Splunk will index and show the data in reverse order Last In First Out (LIFO), you need to decide how the order it for presentation. Assume we want the data as it was originally written to the log file (not the way it was indexed); use &lt;CODE&gt;reverse&lt;/CODE&gt; to align it accordingly.&lt;/P&gt;

&lt;P&gt;Create a new variable called No and use &lt;CODE&gt;accum&lt;/CODE&gt; to increase the variable value by one (1).&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/305iF93DA80B11C69966/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;All together the search looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="answers-1429120234" | reverse | eval No=1 | accum No | table No _raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Good luck and happy Splunking &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;--&lt;BR /&gt;
gc&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2015 18:05:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135026#M27786</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2015-04-15T18:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135027#M27787</link>
      <description>&lt;P&gt;Hi, &lt;BR /&gt;
If there is a way you can have your event in the statistic tab, and if you are using splunk 6.2, you can go in format option and select LINE NUMBER to yes&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2015 23:32:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135027#M27787</guid>
      <dc:creator>stephane_cyrill</dc:creator>
      <dc:date>2015-04-15T23:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to number each line in a multiline event?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135028#M27788</link>
      <description>&lt;P&gt;I love your answer.  It introduced me to two new Splunk functions (reverse and accum) which provide a very simple solution.  Your solution does begin with the assumption that the data has already been broken data with each row as an event before it is indexed.  To apply your solution from my test data where the rows are grouped together into each event when indexed, I would simply alter your solution as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats count AS event_num | rex max_match=0 "(?P&amp;lt;line&amp;gt;[^\n]+)\n+" | mvexpand line | eval line_num=1 | accum line_num | table event_num line_num line
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In addition to your results, this simply adds numbering for each event that each line originally belonged to.  It differs from my eventstats solution in that the numbering does not restart with each new event.  I like my eventstats solution better though.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats count AS event_num | rex max_match=0 "(?P&amp;lt;line&amp;gt;[^\n]+)\n+" | mvexpand line | eventstats count AS line_num by event_num | eval line_new=line_num." - ".line | stats list(line_new) AS line_new by event_num
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Apr 2015 00:50:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-number-each-line-in-a-multiline-event/m-p/135028#M27788</guid>
      <dc:creator>landen99</dc:creator>
      <dc:date>2015-04-16T00:50:16Z</dc:date>
    </item>
  </channel>
</rss>

