<?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: Field extraction of log file -- Each line has different format, how can I include all format in one regex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313258#M93769</link>
    <description>&lt;P&gt;Please check - &lt;BR /&gt;
&lt;CODE&gt;sourcetype="multiplefields" | rex max_match=0 "(?&amp;lt;FIELDS&amp;gt;\S+)[\,|\n]" | table _raw FIELDS&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;you just want to pull all fields and make a table like this photo or some other operations you want to do, please clarify - &lt;BR /&gt;
(PS- on the photo, one or two fields are not picked up, that is due to my sample file.)&lt;BR /&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/3677iE18FCBCD2AE10781/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Oct 2017 03:32:48 GMT</pubDate>
    <dc:creator>inventsekar</dc:creator>
    <dc:date>2017-10-16T03:32:48Z</dc:date>
    <item>
      <title>Field extraction of log file -- Each line has different format, how can I include all format in one regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313257#M93768</link>
      <description>&lt;P&gt;I am doing field extraction for a log file format as below:&lt;BR /&gt;
line 1: field1, field2, field3, field4&lt;BR /&gt;
line 2: field1, field2, field3, field5, field4&lt;BR /&gt;
line 3: field1, field2, field3, field4&lt;/P&gt;

&lt;P&gt;I can write separate regex1 for line 1 and regex 2 for line 2 format, but when I do field extraction, I can only use one regex, how can I put both regex in to cover all log format? Any suggestions?&lt;BR /&gt;
Cheers&lt;BR /&gt;
Sam&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 03:14:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313257#M93768</guid>
      <dc:creator>samlinsongguo</dc:creator>
      <dc:date>2017-10-16T03:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction of log file -- Each line has different format, how can I include all format in one regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313258#M93769</link>
      <description>&lt;P&gt;Please check - &lt;BR /&gt;
&lt;CODE&gt;sourcetype="multiplefields" | rex max_match=0 "(?&amp;lt;FIELDS&amp;gt;\S+)[\,|\n]" | table _raw FIELDS&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;you just want to pull all fields and make a table like this photo or some other operations you want to do, please clarify - &lt;BR /&gt;
(PS- on the photo, one or two fields are not picked up, that is due to my sample file.)&lt;BR /&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/3677iE18FCBCD2AE10781/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 03:32:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313258#M93769</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2017-10-16T03:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction of log file -- Each line has different format, how can I include all format in one regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313259#M93770</link>
      <description>&lt;P&gt;You can use something like the following (the &lt;CODE&gt;rex&lt;/CODE&gt; command is the part you are interested in, and the rest is the setup for showing that it works) :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="line 1: field1, field2, field3, field4
line 2: field1, field2, field3, field5, field4
line 3: field1, field2, field3, field4" 
| makemv raw delim="
"
| mvexpand raw
| rex field=raw "[^:]+:\s*(?P&amp;lt;field1&amp;gt;[^,]+),\s*(?P&amp;lt;field2&amp;gt;[^,]+),\s*(?P&amp;lt;field3&amp;gt;[^,]+),\s*((?P&amp;lt;field5&amp;gt;[^,]+?),\s*?)?+\s*(?P&amp;lt;field4&amp;gt;[^,]+$)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You will probably have to make adjustments for your actual data, but this should get you started on a complete solution.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 04:56:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313259#M93770</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-10-16T04:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction of log file -- Each line has different format, how can I include all format in one regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313260#M93771</link>
      <description>&lt;P&gt;Thank you for all the answers, what I am looking for is more on index / normalize the log when it injected rather than doing field extraction in the search query.&lt;/P&gt;

&lt;P&gt;To achieve my goal, I end up have two field extraction Rex for this sourcetype, it seems give what I want. But I am wondering would that consume too much resource when I inject large mount of logs?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 03:05:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-of-log-file-Each-line-has-different-format-how/m-p/313260#M93771</guid>
      <dc:creator>samlinsongguo</dc:creator>
      <dc:date>2017-10-19T03:05:55Z</dc:date>
    </item>
  </channel>
</rss>

