<?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 based on the element position in a csv in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-based-on-the-element-position-in-a-csv/m-p/163208#M46307</link>
    <description>&lt;P&gt;This will work - but I might put it in a macro so that I could re-use it without typing&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| rex "(?&amp;lt;Date&amp;gt;.*?);(?&amp;lt;id&amp;gt;.*?);(?&amp;lt;disk&amp;gt;.*?);(?&amp;lt;partition&amp;gt;.*?);(?&amp;lt;disktype&amp;gt;.*?);(?&amp;lt;numdisk&amp;gt;.*?);(?&amp;lt;servers&amp;gt;.*?);(?&amp;lt;bwu&amp;gt;.*?);(?&amp;lt;bwt&amp;gt;.*?);(?&amp;lt;bwp&amp;gt;.*?);(?&amp;lt;sizeu&amp;gt;.*?);(?&amp;lt;sizet&amp;gt;.*)"
| whateverelse
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You won't be able to cut-and-paste this unless you remove the line-wrap...&lt;/P&gt;

&lt;P&gt;Finally, the actual regular expression for each field is &lt;CODE&gt;.*?&lt;/CODE&gt; which in this context means "any characters up to but not including the next ;"&lt;/P&gt;

&lt;P&gt;Last but definitely not least: just because you can't manually edit &lt;CODE&gt;props.conf&lt;/CODE&gt; does not mean that you can't create  permanent field extractions. Under Manager or Settings (depending on your version of Splunk), find Fields then look for Field Extractions. Click New. Fill out the form. Make sure the type is Inline, and put the following in the Extraction/Transform:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;Date&amp;gt;.*?);(?&amp;lt;id&amp;gt;.*?);(?&amp;lt;disk&amp;gt;.*?);(?&amp;lt;partition&amp;gt;.*?);(?&amp;lt;disktype&amp;gt;.*?);(?&amp;lt;numdisk&amp;gt;.*?);(?&amp;lt;servers&amp;gt;.*?);(?&amp;lt;bwu&amp;gt;.*?);(?&amp;lt;bwt&amp;gt;.*?);(?&amp;lt;bwp&amp;gt;.*?);(?&amp;lt;sizeu&amp;gt;.*?);(?&amp;lt;sizet&amp;gt;.*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Save it. You may want to set the permissions so that others can use it too. There - you just updated &lt;CODE&gt;props.conf&lt;/CODE&gt;, the hard way IMO &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Dec 2013 08:27:58 GMT</pubDate>
    <dc:creator>lguinn2</dc:creator>
    <dc:date>2013-12-03T08:27:58Z</dc:date>
    <item>
      <title>Field extraction based on the element position in a csv</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-based-on-the-element-position-in-a-csv/m-p/163206#M46305</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have csv files but Splunk can`t auto extact the fields based on headers beacause we've assigned our own sourcetypes and i dont have access to props.conf or other core files, i need to extract the fields using regular expressions.&lt;BR /&gt;
An example of line in my csv is:&lt;/P&gt;

&lt;P&gt;"Date";"id";"disk";"partition";"disktype";"numdisk";"servers";"bwu";"bwt";"bwp";"sizeu";"sizet"&lt;/P&gt;

&lt;P&gt;I need a regex that gives me the value of a field based on the position, maybe based on the number of ; before it regardeless of what's inside " "&lt;/P&gt;

&lt;P&gt;If i use the generate button on a values corresponding to id for exemple i get something like:&lt;/P&gt;

&lt;P&gt;(?i)^(?:[^:]*:){2}\d+";"(?P&lt;FIELDNAME&gt;[^"]+) , how do i change that to have something where i can just add an element or change a value to get the next element&lt;/FIELDNAME&gt;&lt;/P&gt;

&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 22:46:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-based-on-the-element-position-in-a-csv/m-p/163206#M46305</guid>
      <dc:creator>tallasky</dc:creator>
      <dc:date>2013-12-02T22:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction based on the element position in a csv</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-based-on-the-element-position-in-a-csv/m-p/163207#M46306</link>
      <description>&lt;P&gt;I tested with sample data and following seems to be working for me.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=yourindex sourcetype=yoursourcetype | rex "(?i)^(?:[^;]*;){0}\"(?P&amp;lt;field1&amp;gt;[^\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Field index will start from 1 and number within curly brackets will start from 0.&lt;BR /&gt;
So &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;for field 1 "(?i)^(?:[^;]*;){0}\"(?P&amp;lt;field1&amp;gt;[^\"]+)"
for field 2 "(?i)^(?:[^;]*;){1}\"(?P&amp;lt;field2&amp;gt;[^\"]+)"
for field 3 "(?i)^(?:[^;]*;){2}\"(?P&amp;lt;field3&amp;gt;[^\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2013 23:50:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-based-on-the-element-position-in-a-csv/m-p/163207#M46306</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2013-12-02T23:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Field extraction based on the element position in a csv</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Field-extraction-based-on-the-element-position-in-a-csv/m-p/163208#M46307</link>
      <description>&lt;P&gt;This will work - but I might put it in a macro so that I could re-use it without typing&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| rex "(?&amp;lt;Date&amp;gt;.*?);(?&amp;lt;id&amp;gt;.*?);(?&amp;lt;disk&amp;gt;.*?);(?&amp;lt;partition&amp;gt;.*?);(?&amp;lt;disktype&amp;gt;.*?);(?&amp;lt;numdisk&amp;gt;.*?);(?&amp;lt;servers&amp;gt;.*?);(?&amp;lt;bwu&amp;gt;.*?);(?&amp;lt;bwt&amp;gt;.*?);(?&amp;lt;bwp&amp;gt;.*?);(?&amp;lt;sizeu&amp;gt;.*?);(?&amp;lt;sizet&amp;gt;.*)"
| whateverelse
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You won't be able to cut-and-paste this unless you remove the line-wrap...&lt;/P&gt;

&lt;P&gt;Finally, the actual regular expression for each field is &lt;CODE&gt;.*?&lt;/CODE&gt; which in this context means "any characters up to but not including the next ;"&lt;/P&gt;

&lt;P&gt;Last but definitely not least: just because you can't manually edit &lt;CODE&gt;props.conf&lt;/CODE&gt; does not mean that you can't create  permanent field extractions. Under Manager or Settings (depending on your version of Splunk), find Fields then look for Field Extractions. Click New. Fill out the form. Make sure the type is Inline, and put the following in the Extraction/Transform:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;Date&amp;gt;.*?);(?&amp;lt;id&amp;gt;.*?);(?&amp;lt;disk&amp;gt;.*?);(?&amp;lt;partition&amp;gt;.*?);(?&amp;lt;disktype&amp;gt;.*?);(?&amp;lt;numdisk&amp;gt;.*?);(?&amp;lt;servers&amp;gt;.*?);(?&amp;lt;bwu&amp;gt;.*?);(?&amp;lt;bwt&amp;gt;.*?);(?&amp;lt;bwp&amp;gt;.*?);(?&amp;lt;sizeu&amp;gt;.*?);(?&amp;lt;sizet&amp;gt;.*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Save it. You may want to set the permissions so that others can use it too. There - you just updated &lt;CODE&gt;props.conf&lt;/CODE&gt;, the hard way IMO &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2013 08:27:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Field-extraction-based-on-the-element-position-in-a-csv/m-p/163208#M46307</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-12-03T08:27:58Z</dc:date>
    </item>
  </channel>
</rss>

