<?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: Splunk  - Flat file - Field Extraction - Transforms.conf in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Splunk-Flat-file-Field-Extraction-Transforms-conf/m-p/191893#M38239</link>
    <description>&lt;P&gt;One problem with your REGEX above is that you state that there is a non-space character between your fields. Perhaps you want to use &lt;CODE&gt;\s&lt;/CODE&gt; instead of &lt;CODE&gt;\S&lt;/CODE&gt;? Also, if you want to use that regex, I suggest you change it a little and put it in a normal EXTRACT in props.conf only, like so;&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype]
EXTRACT-blah = ^(?P&amp;lt;ID&amp;gt;.{10})\s+(?&amp;lt;FIRST_NAME&amp;gt;.{15})\s+(?&amp;lt;LAST_NAME&amp;gt;.{12})\s+(?&amp;lt;ADDRESS&amp;gt;.{25})\s+(?&amp;lt;PHONE&amp;gt;.{10})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works well for logs like;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1234567890 gregor          von klopp   1, high street            1-555-2345
345323     billy bob ben   joe         buckingham palace, london +44 123123
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So as you can see, this approach requires you to have fixed length fields in your log file.   &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;If your fields do NOT contain spaces, and you have a delimiter that is a single space, it could also be done (better) with a REPORT (which uses transforms.conf);&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype]
REPORT-blah = extract_blah
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[extract_blah]
DELIMS = " "
FIELDS = ID, FIRST_NAME, LAST_NAME, ADDRESS, PHONE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, you can do the same thing by changing the regex and use an ordinary EXTRACT that does not require fixed length fields;&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype]
EXTRACT-bleh = ^(?P&amp;lt;ID&amp;gt;\S+)\s+(?&amp;lt;FIRST_NAME&amp;gt;\S+)\s+(?&amp;lt;LAST_NAME&amp;gt;\S+)\s+(?&amp;lt;ADDRESS&amp;gt;\S+)\s+(?&amp;lt;PHONE&amp;gt;\S+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These two approaches work with events like;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1234123 gregor von_klopp 1,high_street 1-555-2345
23421 billy_bob_ben joe buckingham_palace,london +44123123
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Makes sense? &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;If you have truly fixed fields, and the field content is truncated if it's above a certain field length, you'd better use the first approach and remove the delimiters from the regex, i.e.&lt;/P&gt;

&lt;P&gt;file looks like;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;12345678  HM Queen ElizabN/A         Buckingham Palace, London+44123123
0987654321Arnold         Schwarzenegg25, Fifth avenue, NY     +1-555-123
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-blah = ^(?P&amp;lt;ID&amp;gt;.{10})(?&amp;lt;FIRST_NAME&amp;gt;.{15})(?&amp;lt;LAST_NAME&amp;gt;.{12})(?&amp;lt;ADDRESS&amp;gt;.{25})(?&amp;lt;PHONE&amp;gt;.{10})
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 18 Mar 2014 09:57:54 GMT</pubDate>
    <dc:creator>kristian_kolb</dc:creator>
    <dc:date>2014-03-18T09:57:54Z</dc:date>
    <item>
      <title>Splunk  - Flat file - Field Extraction - Transforms.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Splunk-Flat-file-Field-Extraction-Transforms-conf/m-p/191892#M38238</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I want to extract the fields using transforms.conf from a flat file. The file contains the following fields. There is no field delimiter. I have tried the below regex but not working. pls help me.&lt;/P&gt;

&lt;P&gt;Field Length: &lt;BR /&gt;
ID -10&lt;BR /&gt;
FIRST_NAME -15&lt;BR /&gt;
LAST_NAME -12&lt;BR /&gt;
ADDRESS - 25&lt;BR /&gt;
PHONE - 10&lt;/P&gt;

&lt;P&gt;Example File1:&lt;/P&gt;

&lt;P&gt;ID        FIRST_NAME    LAST_NAME   ADDRESS                  PHONE&lt;BR /&gt;
0000001  Name1           Lastname1  Address1                       1234567890&lt;BR /&gt;&lt;BR /&gt;
00000021  name2                      Address2                123456&lt;BR /&gt;
001           name3                  Address3                         &lt;/P&gt;

&lt;HR /&gt;

&lt;PRE&gt;&lt;CODE&gt;REGEX = (?i)^(?P&amp;lt;ID&amp;gt;.{10})\S(?&amp;lt;FIRST_NAME&amp;gt;.{15})\S(?&amp;lt;LAST_NAME&amp;gt;.{12})\S(?&amp;lt;ADDRESS&amp;gt;.{25})\S(?&amp;lt;PHONE&amp;gt;.{10})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
V.S&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:09:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Splunk-Flat-file-Field-Extraction-Transforms-conf/m-p/191892#M38238</guid>
      <dc:creator>vasanthmss</dc:creator>
      <dc:date>2020-09-28T16:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk  - Flat file - Field Extraction - Transforms.conf</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Splunk-Flat-file-Field-Extraction-Transforms-conf/m-p/191893#M38239</link>
      <description>&lt;P&gt;One problem with your REGEX above is that you state that there is a non-space character between your fields. Perhaps you want to use &lt;CODE&gt;\s&lt;/CODE&gt; instead of &lt;CODE&gt;\S&lt;/CODE&gt;? Also, if you want to use that regex, I suggest you change it a little and put it in a normal EXTRACT in props.conf only, like so;&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype]
EXTRACT-blah = ^(?P&amp;lt;ID&amp;gt;.{10})\s+(?&amp;lt;FIRST_NAME&amp;gt;.{15})\s+(?&amp;lt;LAST_NAME&amp;gt;.{12})\s+(?&amp;lt;ADDRESS&amp;gt;.{25})\s+(?&amp;lt;PHONE&amp;gt;.{10})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works well for logs like;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1234567890 gregor          von klopp   1, high street            1-555-2345
345323     billy bob ben   joe         buckingham palace, london +44 123123
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So as you can see, this approach requires you to have fixed length fields in your log file.   &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;If your fields do NOT contain spaces, and you have a delimiter that is a single space, it could also be done (better) with a REPORT (which uses transforms.conf);&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype]
REPORT-blah = extract_blah
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[extract_blah]
DELIMS = " "
FIELDS = ID, FIRST_NAME, LAST_NAME, ADDRESS, PHONE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, you can do the same thing by changing the regex and use an ordinary EXTRACT that does not require fixed length fields;&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[your_sourcetype]
EXTRACT-bleh = ^(?P&amp;lt;ID&amp;gt;\S+)\s+(?&amp;lt;FIRST_NAME&amp;gt;\S+)\s+(?&amp;lt;LAST_NAME&amp;gt;\S+)\s+(?&amp;lt;ADDRESS&amp;gt;\S+)\s+(?&amp;lt;PHONE&amp;gt;\S+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These two approaches work with events like;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;1234123 gregor von_klopp 1,high_street 1-555-2345
23421 billy_bob_ben joe buckingham_palace,london +44123123
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Makes sense? &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;If you have truly fixed fields, and the field content is truncated if it's above a certain field length, you'd better use the first approach and remove the delimiters from the regex, i.e.&lt;/P&gt;

&lt;P&gt;file looks like;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;12345678  HM Queen ElizabN/A         Buckingham Palace, London+44123123
0987654321Arnold         Schwarzenegg25, Fifth avenue, NY     +1-555-123
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;EXTRACT-blah = ^(?P&amp;lt;ID&amp;gt;.{10})(?&amp;lt;FIRST_NAME&amp;gt;.{15})(?&amp;lt;LAST_NAME&amp;gt;.{12})(?&amp;lt;ADDRESS&amp;gt;.{25})(?&amp;lt;PHONE&amp;gt;.{10})
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Mar 2014 09:57:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Splunk-Flat-file-Field-Extraction-Transforms-conf/m-p/191893#M38239</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2014-03-18T09:57:54Z</dc:date>
    </item>
  </channel>
</rss>

