<?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: Regex to extract fields from CSV file based on number of delimiters? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215743#M63264</link>
    <description>&lt;P&gt;i am afraid we cannot do so.....i need a regex to count the delimiters first and then based on the condition of the number of delimiters extract the fields accordingly.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Sep 2015 16:44:28 GMT</pubDate>
    <dc:creator>nancylawrence00</dc:creator>
    <dc:date>2015-09-09T16:44:28Z</dc:date>
    <item>
      <title>Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215732#M63253</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have two types of logs:&lt;/P&gt;

&lt;P&gt;Log1: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Log2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;DATABASE01;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If i use &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^([^;]*;){10}(?&amp;lt;Field_Name&amp;gt;[^;]*) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;based on the number of delimiters &lt;CODE&gt;;&lt;/CODE&gt;, I get wrong output from Log2 as there is an Extra field (DATABASE01)&lt;/P&gt;

&lt;P&gt;I need to count the number of delimiters and then extract the field based on the count.&lt;/P&gt;

&lt;P&gt;Please advice.&lt;/P&gt;

&lt;P&gt;Thanks &lt;BR /&gt;
Nancy&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2015 19:26:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215732#M63253</guid>
      <dc:creator>nancylawrence00</dc:creator>
      <dc:date>2015-09-07T19:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215733#M63254</link>
      <description>&lt;P&gt;Hi nancylawrence007,&lt;/P&gt;

&lt;P&gt;Or you start from the end of the event, if the end is always &lt;CODE&gt;;VPN;&lt;/CODE&gt; you can use this regex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;;(?&amp;lt;Event_TimeStamp&amp;gt;\d+:\d+);VPN;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2015 20:33:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215733#M63254</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-09-07T20:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215734#M63255</link>
      <description>&lt;P&gt;Nice answer MuS.&lt;/P&gt;

&lt;P&gt;Just thinking that if the event ending is different, then you may also be able to just extract the time with something like this (if no other fields match the time pattern) .&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... |eval Event_TimeStamp=_raw |rex mode=sed field=Event_TimeStamp "s/([^;]+;)+(\d\d:\d\d)(;.*$)/\2/"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Sep 2015 22:00:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215734#M63255</guid>
      <dc:creator>gcato</dc:creator>
      <dc:date>2015-09-07T22:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215735#M63256</link>
      <description>&lt;P&gt;Though, thinking about it again, if the field time pattern is unique across all fields, then you do not need to worry about the number of delimiters (or sed) and the following would work too&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; rex "([^;]+;)+(?\d\d:\d\d);"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Sep 2015 22:30:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215735#M63256</guid>
      <dc:creator>gcato</dc:creator>
      <dc:date>2015-09-07T22:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215736#M63257</link>
      <description>&lt;P&gt;Logs above are just examples, exact logs differ but are separated by delimiters&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2015 23:29:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215736#M63257</guid>
      <dc:creator>nancylawrence00</dc:creator>
      <dc:date>2015-09-07T23:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215737#M63258</link>
      <description>&lt;P&gt;either provide the exact log events or try the second regex mentioned by @gcato &lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2015 23:34:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215737#M63258</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-09-07T23:34:38Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215738#M63259</link>
      <description>&lt;P&gt;Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;10.81.5.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2015 23:46:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215738#M63259</guid>
      <dc:creator>nancylawrence00</dc:creator>
      <dc:date>2015-09-07T23:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215739#M63260</link>
      <description>&lt;P&gt;thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; in this example, where is the needed time ?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2015 23:52:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215739#M63260</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-09-07T23:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215740#M63261</link>
      <description>&lt;P&gt;sorry to ask again, but which is the value you want to get for both examples? &lt;BR /&gt;
Your regex captures from Log1:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;9599;LEC Audit - SYSTEM Logins
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and from Log2:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;9580;9599
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you don't provide this information there is no way to help you with this problem.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2015 20:29:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215740#M63261</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-09-08T20:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215741#M63262</link>
      <description>&lt;P&gt;i need to extract all the fields &lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 10:34:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215741#M63262</guid>
      <dc:creator>nancylawrence00</dc:creator>
      <dc:date>2015-09-09T10:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215742#M63263</link>
      <description>&lt;P&gt;Each log should be a separate sourcetype with appropriate extractions created for them.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 12:21:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215742#M63263</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-09-09T12:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215743#M63264</link>
      <description>&lt;P&gt;i am afraid we cannot do so.....i need a regex to count the delimiters first and then based on the condition of the number of delimiters extract the fields accordingly.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 16:44:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215743#M63264</guid>
      <dc:creator>nancylawrence00</dc:creator>
      <dc:date>2015-09-09T16:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215744#M63265</link>
      <description>&lt;P&gt;Sorry to say, but you're contradicting yourself with your comments. Once you need to count the &lt;CODE&gt;;&lt;/CODE&gt; and extract fields based on the count, in the next comment you want all fields?!?! It's pretty hard to help this way and since most of use are doing this voluntarily, it would be nice to provide precise information....other wise it's like asking the magic 8-ball&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 20:29:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215744#M63265</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-09-09T20:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215745#M63266</link>
      <description>&lt;P&gt;Not exactly sure what you want, but maybe splitting the events into multivalue fields and then using multivalue eval commands will get the results you need. If will certainly give you a count of the number of fields.&lt;/P&gt;

&lt;P&gt;Anyway, here are some examples of how to use eval's mv commands to extract fields and will hopefully get you going (ignore the first half which is just creating the test output). &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|stats count as logs | eval logs="Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;|Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;DATABASE01;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;" 
| eval logs=split(logs, "|") |mvexpand logs
| eval fields = split(logs, ";") 
| eval n1 = mvfind(fields, "LEC.*") | eval extract_field1 = mvindex(fields, n1)
| eval n2 = mvfind(fields, "CONNECT") | eval extract_field2 = mvindex(fields, n1,n2)
| eval n3 = mvfind(fields, "DATABASE\d+") | eval n3=if(isnull(n3), 5, n3) | eval extract_field3 = mvindex(fields, n3+1)
| eval c = mvcount(fields)
| eval extract_field4 = case (c==31, mvindex(fields, c-3), c==32, mvindex(fields, c-3))
| ... &amp;lt;etc&amp;gt; ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also refer to the eval comand in the docs for further reference and even more mv commands that you can use to hopefully get the results you want. &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.5/SearchReference/CommonEvalFunctions#Multivalue_functions"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.5/SearchReference/CommonEvalFunctions#Multivalue_functions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2015 23:18:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215745#M63266</guid>
      <dc:creator>gcato</dc:creator>
      <dc:date>2015-09-09T23:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215746#M63267</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have to extract all the fields by:&lt;/P&gt;

&lt;P&gt;^([^;]&lt;EM&gt;;){1}(?[^;]&lt;/EM&gt;)&lt;BR /&gt;
^([^;]&lt;EM&gt;;){2}(?[^;]&lt;/EM&gt;)&lt;BR /&gt;
^([^;]&lt;EM&gt;;){3}(?[^;]&lt;/EM&gt;) and so on......&lt;/P&gt;

&lt;P&gt;the issue is that i have an extra field in middle of the log and the above regex extracts the wrong field once it gets to the extra field in some of my logs.......&lt;/P&gt;

&lt;P&gt;For further info i here are the logs....&lt;/P&gt;

&lt;P&gt;Log1:&lt;BR /&gt;
Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;&lt;/P&gt;

&lt;P&gt;Log2:&lt;BR /&gt;
 Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;DATABASE01;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;&lt;/P&gt;

&lt;P&gt;You see there is an extra field in Log2 (Database1), so when i use the regex mentioned above the numbering changes and thus pulls up the wrong field.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2015 07:17:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215746#M63267</guid>
      <dc:creator>nancylawrence00</dc:creator>
      <dc:date>2015-09-12T07:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215747#M63268</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I can extract all the fields by:&lt;/P&gt;

&lt;P&gt;^([^;]&lt;EM&gt;;){1}(?[^;]&lt;/EM&gt;)&lt;BR /&gt;
^([^;]&lt;EM&gt;;){2}(?[^;]&lt;/EM&gt;)&lt;BR /&gt;
^([^;]&lt;EM&gt;;){3}(?[^;]&lt;/EM&gt;) and so on......&lt;/P&gt;

&lt;P&gt;the issue is that i have an extra field in middle of the log and the above regex extracts the wrong field once it gets to the extra field in some of my logs.......&lt;/P&gt;

&lt;P&gt;For further info i here are the logs....&lt;/P&gt;

&lt;P&gt;Log1:&lt;BR /&gt;
Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;&lt;/P&gt;

&lt;P&gt;Log2:&lt;BR /&gt;
 Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;DATABASE01;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;&lt;/P&gt;

&lt;P&gt;You see there is an extra field in Log2 (Database1), so when i use the regex mentioned above the numbering changes and thus pulls up the wrong field.&lt;/P&gt;</description>
      <pubDate>Sat, 12 Sep 2015 07:17:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215747#M63268</guid>
      <dc:creator>nancylawrence00</dc:creator>
      <dc:date>2015-09-12T07:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Regex to extract fields from CSV file based on number of delimiters?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215748#M63269</link>
      <description>&lt;P&gt;Hi nancylawrence007,&lt;/P&gt;

&lt;P&gt;I understand the issue but I'm still not sure what you exactly want from the examples provided. As far as I know regex cannot count delimiters, so that is not an option. Basically, you need to normalise the logs so they always have the same number of fields, for which the sed command is perfect. So either,&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;add an extra ";" between "field6;field_7" in log1 (32 fields), or&lt;/LI&gt;
&lt;LI&gt;substitute the ";" before DATABASE01 field in log2 (31 fields), or&lt;/LI&gt;
&lt;LI&gt;remove the ";DATABASE01" section (31 fields)&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I'd recommend #1, as #2 means you would need to perform another regex on the substituted field to extract its two values, and #3 removes a field (though it could be extracted earlier). Anyway, the "rex mode=sed ..." run anywhere example below would do the trick (assuming log1's 6 &amp;amp; 7 fields are consistently a "number;ip_addr") for #1 option.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |stats count as logs | eval logs="Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;|Jun 18 14:10:57 lec05674568 ABC[455135]: 2015-06-18 14:10:57;indexserver;lec056741;XBE;06;30893;DATABASE01;11.91.6.128;lec056287312;9580;9599;LEC Audit - SYSTEM Logins;CRITICAL;CONNECT;SYSTEM;;;;;;DAPNAPS;UNSUCCESSFUL;;;;;;invalid username or password;;5562789;;"
 | eval logs=split(logs, "|") |mvexpand logs
 | rex mode=sed field=logs "s/((?:[^;]+;){5}\d+;)(\d+\.\d+\.\d+\.\d+;.*)/\1;\2/"
 | eval log_fields=split(logs, ";") |eval field_count = mvcount(log_fields)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, both logs have the same number of fields (as the field_count shows) and whatever regex extraction you are using will work.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 05:16:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Regex-to-extract-fields-from-CSV-file-based-on-number-of/m-p/215748#M63269</guid>
      <dc:creator>gcato</dc:creator>
      <dc:date>2015-09-16T05:16:46Z</dc:date>
    </item>
  </channel>
</rss>

