<?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 extract fields from my raw data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-raw-data/m-p/267044#M80354</link>
    <description>&lt;P&gt;Don't feel like you have to do it all in one rex command.&lt;/P&gt;

&lt;P&gt;You could do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "MSIAuth,.*,(?&amp;lt;result&amp;gt;SUCCESS|FAILURE),"
| rex "MSIAuth,.*,FAILURE,.*,(?&amp;lt;failure_cause&amp;gt;[^,]+),"
| rex "MSIAuth,.*,SUCCESS,(?&amp;lt;success_services&amp;gt;[^,]+),"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can also do some testing by using makeresults, eval &amp;amp; append to create your test data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 
| eval text="2017-02-01T15:17:02.057Z,au:23,MSIAuth,24.27.228.162,!xxxyyy@aaa.company.com,xxxyyy,0/0/0/840,nycmny83-cr01ras01.wifi.rr.com,54-26-96-1B-54-BC,74-3E-2B-2E-16-20:CableWiFi,,,,CableWiFi,95ms,0A440002060000000BD71DFC,86400,,SUCCESS,TWCULTIMATEINTERNET300,ServiceName:ABWAUTHSVC01" 
| append 
    [| makeresults count=1 
    | eval text="2017-02-01T15:17:01.867Z,au:16,MSIAuth,24.27.228.162,!xxxyyy@aaa.company.com,xxxyyy,0/0/0/840,nycmny83-cr01ras01.wifi.rr.com,54-26-96-1B-54-BC,,,,,CableWiFi,62ms,0A440002060000000BD71DC4,86400,,FAILURE,TWCULTIMATEINTERNET300,DeviceLimit,FAILURE -- FAILURE -- Failure response from 75.180.151.70:1812"]
| rename text as _raw
| rex "MSIAuth,.*,(?&amp;lt;result&amp;gt;SUCCESS|FAILURE),"
| rex "MSIAuth,.*,FAILURE,.*,(?&amp;lt;failure_cause&amp;gt;[^,]+),"
| rex "MSIAuth,.*,SUCCESS,(?&amp;lt;success_services&amp;gt;[^,]+),"
&lt;/CODE&gt;&lt;/PRE&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/2408i43B00B9A0B1A9DA3/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;BR /&gt;
(ignore _time in this example; this is created by makeresults. You're just testing your extractions)&lt;/P&gt;

&lt;P&gt;The rex statements in the example are fairly 'loose', but if you know your data, you can make them more specific as required.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2017 05:29:16 GMT</pubDate>
    <dc:creator>gvmorley</dc:creator>
    <dc:date>2017-02-02T05:29:16Z</dc:date>
    <item>
      <title>How to extract fields from my raw data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-raw-data/m-p/267042#M80352</link>
      <description>&lt;P&gt;Need help to extract fields between comma (,). The raw data below have two results, FAILURE and SUCCESS. I want to create some select fields and stats them in to a table. So far I was able to use following regular expression, and extracted USERNAME ( in this example "xxxyyy" is the username extracted from 5th and 6th comma),   MACADDRESS (in this example "54-26-96-1B-54-BC" extracted between 8th and 9th comma). Here are the challenges I am facing when I want to to extract SUCCESS/FAILURE and cause fields :&lt;/P&gt;

&lt;P&gt;For SUCCESS, I want to extract SUCCESS between 18th and 19th comma, and the services field between 19th and 20th comma.&lt;BR /&gt;
For FAILURE, I want to extract FAILURE between 17th and 18th comma, and cause field between 19th and 20th comma.&lt;/P&gt;

&lt;P&gt;SUCCESS :&lt;BR /&gt;
2017-02-01T15:17:02.057Z,au:23,MSIAuth,24.27.228.162,!&lt;A href="mailto:xxxyyy@aaa.company.com"&gt;xxxyyy@aaa.company.com&lt;/A&gt;,xxxyyy,0/0/0/840,nycmny83-cr01ras01.wifi.rr.com,54-26-96-1B-54-BC,74-3E-2B-2E-16-20:CableWiFi,,,,CableWiFi,95ms,0A440002060000000BD71DFC,86400,,SUCCESS,TWCULTIMATEINTERNET300,ServiceName:ABWAUTHSVC01&lt;/P&gt;

&lt;P&gt;FAILURE:&lt;BR /&gt;
2017-02-01T15:17:01.867Z,au:16,MSIAuth,24.27.228.162,!&lt;A href="mailto:xxxyyy@aaa.company.com"&gt;xxxyyy@aaa.company.com&lt;/A&gt;,xxxyyy,0/0/0/840,nycmny83-cr01ras01.wifi.rr.com,54-26-96-1B-54-BC,,,,,CableWiFi,62ms,0A440002060000000BD71DC4,86400,,FAILURE,TWCULTIMATEINTERNET300,DeviceLimit,FAILURE -- FAILURE -- Failure response from 75.180.151.70:1812&lt;/P&gt;

&lt;P&gt;So, far following regex provided me a table with TIME STAMP, MACADDRESS and USERNAME (like I mentioned above) :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="aaa-AuthAttempts" MSIAuth NOT TWCWiFi-Passpoint failure | rex "MSIAuth\,\d+\.\d+\.\d+\.\d+\,(?[^\,]+)\,(?[^\,]+)\,0\/0\/0\/\d+\,\w{6}\d+\-\w{2}\d+\w+\d+\.\w+\.\w+\.\w+\,(?[^\,]+)" | stats count by _time , MACADDRESS, USERNAME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Can anyone please help to add columns in the table with SUCCESS, FAILURE and other fields based on the pattern of the raw data outlined above ? Such as :&lt;/P&gt;

&lt;P&gt;For SUCCESS, I want to extract SUCCESS between 18th and 19th comma, and the services field between 19th and 20th comma.&lt;BR /&gt;
For FAILURE, I want to extract FAILURE between 17th and 18th comma, and cause field between 19th and 20th comma.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Feb 2017 15:41:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-raw-data/m-p/267042#M80352</guid>
      <dc:creator>rafiqul</dc:creator>
      <dc:date>2017-02-01T15:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract fields from my raw data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-raw-data/m-p/267043#M80353</link>
      <description>&lt;P&gt;This is probably not the most elegant solution, but it works on regex101.com with your sample events.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "MSIAuth,\d+\.\d+\.\d+\.\d+,(?&amp;lt;field1&amp;gt;[^,]+),(?&amp;lt;username&amp;gt;[^,]+),0\/0\/0\/\d+,\w{6}\d+-\w{2}\d+\w+\d+.\w+.\w+.\w+,(?&amp;lt;MAC&amp;gt;[^,]+),[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,(?&amp;lt;status&amp;gt;[^,]*),(?&amp;lt;cause&amp;gt;[^,]*),(?&amp;lt;failureReason&amp;gt;[^,\n]*)" | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Feb 2017 17:22:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-raw-data/m-p/267043#M80353</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-02-01T17:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract fields from my raw data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-raw-data/m-p/267044#M80354</link>
      <description>&lt;P&gt;Don't feel like you have to do it all in one rex command.&lt;/P&gt;

&lt;P&gt;You could do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "MSIAuth,.*,(?&amp;lt;result&amp;gt;SUCCESS|FAILURE),"
| rex "MSIAuth,.*,FAILURE,.*,(?&amp;lt;failure_cause&amp;gt;[^,]+),"
| rex "MSIAuth,.*,SUCCESS,(?&amp;lt;success_services&amp;gt;[^,]+),"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can also do some testing by using makeresults, eval &amp;amp; append to create your test data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 
| eval text="2017-02-01T15:17:02.057Z,au:23,MSIAuth,24.27.228.162,!xxxyyy@aaa.company.com,xxxyyy,0/0/0/840,nycmny83-cr01ras01.wifi.rr.com,54-26-96-1B-54-BC,74-3E-2B-2E-16-20:CableWiFi,,,,CableWiFi,95ms,0A440002060000000BD71DFC,86400,,SUCCESS,TWCULTIMATEINTERNET300,ServiceName:ABWAUTHSVC01" 
| append 
    [| makeresults count=1 
    | eval text="2017-02-01T15:17:01.867Z,au:16,MSIAuth,24.27.228.162,!xxxyyy@aaa.company.com,xxxyyy,0/0/0/840,nycmny83-cr01ras01.wifi.rr.com,54-26-96-1B-54-BC,,,,,CableWiFi,62ms,0A440002060000000BD71DC4,86400,,FAILURE,TWCULTIMATEINTERNET300,DeviceLimit,FAILURE -- FAILURE -- Failure response from 75.180.151.70:1812"]
| rename text as _raw
| rex "MSIAuth,.*,(?&amp;lt;result&amp;gt;SUCCESS|FAILURE),"
| rex "MSIAuth,.*,FAILURE,.*,(?&amp;lt;failure_cause&amp;gt;[^,]+),"
| rex "MSIAuth,.*,SUCCESS,(?&amp;lt;success_services&amp;gt;[^,]+),"
&lt;/CODE&gt;&lt;/PRE&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/2408i43B00B9A0B1A9DA3/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;BR /&gt;
(ignore _time in this example; this is created by makeresults. You're just testing your extractions)&lt;/P&gt;

&lt;P&gt;The rex statements in the example are fairly 'loose', but if you know your data, you can make them more specific as required.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 05:29:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-fields-from-my-raw-data/m-p/267044#M80354</guid>
      <dc:creator>gvmorley</dc:creator>
      <dc:date>2017-02-02T05:29:16Z</dc:date>
    </item>
  </channel>
</rss>

