<?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 edit my regular expression to grab the first line in a log? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266767#M80217</link>
    <description>&lt;P&gt;This should do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "somestring :(?P&amp;lt;type&amp;gt;[^\n]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Dec 2016 03:11:59 GMT</pubDate>
    <dc:creator>mrgibbon</dc:creator>
    <dc:date>2016-12-07T03:11:59Z</dc:date>
    <item>
      <title>How to edit my regular expression to grab the first line in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266766#M80216</link>
      <description>&lt;P&gt;I have a log file like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Type: something/something; something
The next line
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to write a Splunk search to grab the first line and create a pie chart of the various different types. The problem is the query I wrote is taking in &lt;CODE&gt;The next line&lt;/CODE&gt; bit too which I don't want. Here's my query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;("Type: " OR "type: ") | rex field=_raw "(?&amp;lt;type&amp;gt;.*)\n" | stats count by type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I write a search that takes everything after the &lt;CODE&gt;:&lt;/CODE&gt; but stops at the newline &lt;CODE&gt;\n&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 03:09:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266766#M80216</guid>
      <dc:creator>sankarms</dc:creator>
      <dc:date>2016-12-07T03:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my regular expression to grab the first line in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266767#M80217</link>
      <description>&lt;P&gt;This should do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "somestring :(?P&amp;lt;type&amp;gt;[^\n]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Dec 2016 03:11:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266767#M80217</guid>
      <dc:creator>mrgibbon</dc:creator>
      <dc:date>2016-12-07T03:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my regular expression to grab the first line in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266768#M80218</link>
      <description>&lt;P&gt;Try this please:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your query to return events
|  rex "Type:\s*(?&amp;lt;myType&amp;gt;[^\n\r]+)"
| stats count by myType
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Use visualization as Pie Chart&lt;/P&gt;

&lt;P&gt;&lt;A href="https://regex101.com/r/jnn3ws/1"&gt;See extraction here&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 03:20:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266768#M80218</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-12-07T03:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my regular expression to grab the first line in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266769#M80219</link>
      <description>&lt;P&gt;So would my search be:&lt;/P&gt;

&lt;P&gt;("Type: " OR "type: ") | rex field=_raw "(?P[^\n]+)" | stats count by type&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 03:33:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266769#M80219</guid>
      <dc:creator>sankarms</dc:creator>
      <dc:date>2016-12-07T03:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my regular expression to grab the first line in a log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266770#M80220</link>
      <description>&lt;P&gt;As per regular expression standards, dot matches any single character except newline character provided regex is run with &lt;STRONG&gt;multiline (?m)&lt;/STRONG&gt; regex flag. Following should work for you. You also need to specify match pattern to identify beginning of regular expression extraction i.e. &lt;STRONG&gt;Type:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=_raw "(?m)Type:\s(?&amp;lt;type&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: By default the regex flag is single line(?s), then dot matches newline character as well, hence you are seeing all the text selected, event from the second line.&lt;/P&gt;

&lt;P&gt;Also once you have tested the rex command, make sure you move this from your search query to Knowledge object as a Field Extraction, for easy maintenance.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 07:32:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-regular-expression-to-grab-the-first-line-in-a/m-p/266770#M80220</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2016-12-07T07:32:25Z</dc:date>
    </item>
  </channel>
</rss>

