<?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 can I dynamically split my sample data using regex or any other options are available? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121408#M32672</link>
    <description>&lt;P&gt;Hai Woodcock,&lt;/P&gt;

&lt;P&gt;Thank you very much.&lt;BR /&gt;
I will try it with another sample file.&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jul 2015 19:25:03 GMT</pubDate>
    <dc:creator>Shan</dc:creator>
    <dc:date>2015-07-14T19:25:03Z</dc:date>
    <item>
      <title>How can I dynamically split my sample data using regex or any other options are available?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121404#M32668</link>
      <description>&lt;P&gt;I have data in a log file as mentioned below. Can I split it using regex or any other options are available?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;0010213002040538
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to split the data above like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;001 02 13 
002 04 0538 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For example, we can take:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;001 02 13 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;001 is a transaction code &lt;BR /&gt;
02  is length of next value's value &lt;BR /&gt;
13  is the value&lt;/P&gt;

&lt;P&gt;Based on the length, I need to split the value dynamically.&lt;/P&gt;

&lt;P&gt;So, how can I dynamically write the rex search to split it? If "02" appears as the length, I need to use that length and split the next value "13".&lt;BR /&gt;
If the length is "04" then, I need to split based on the length to get "0538".&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;BR /&gt;
Kindly help me.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2015 10:03:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121404#M32668</guid>
      <dc:creator>Shan</dc:creator>
      <dc:date>2015-07-14T10:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: How can I dynamically split my sample data using regex or any other options are available?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121405#M32669</link>
      <description>&lt;P&gt;Not with a single &lt;CODE&gt;rex&lt;/CODE&gt; but with this chain of commands:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | rex "(?&amp;lt;TransactionCode&amp;gt;.{3})(?&amp;lt;FieldValueLen&amp;gt;.{2})(?&amp;lt;FieldValue&amp;gt;.*)" | eval FieldValue=substr(FieldValue,1,FieldValueLen)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jul 2015 14:54:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121405#M32669</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-07-14T14:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I dynamically split my sample data using regex or any other options are available?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121406#M32670</link>
      <description>&lt;P&gt;Woodcock,&lt;/P&gt;

&lt;P&gt;First of all. Thank you very much for your valuable reply.&lt;BR /&gt;
When I use the above rex search, it's splitting the first value and stopped there itself. How can I make use of the same rex for multiple value separation?&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Sample data:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;001021300204053800309123d5-78900404data00503get
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Current Search:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=testrex | table * | rex field=_raw "(?&amp;amp;lt;TransactionCode&amp;amp;gt;.{3})(?&amp;lt;FieldValueLen&amp;gt;.{2})(?&amp;lt;FieldValue&amp;gt;.&amp;amp;#42;)" | eval FieldValue=substr(FieldValue,1,FieldValueLen) | table TransactionCode FieldValueLen FieldValue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Desired Result:&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;001 02 13&lt;BR /&gt;
002 04 0538 &lt;BR /&gt;
003 09 123d5-789&lt;BR /&gt;
004 04 data&lt;BR /&gt;
005 03 get&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Current Result:&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;TransactionCode FieldValueLen   FieldValue&lt;BR /&gt;
001                           02                        13&lt;BR /&gt;
001                           02                        13&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Shankar&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2015 16:34:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121406#M32670</guid>
      <dc:creator>Shan</dc:creator>
      <dc:date>2015-07-14T16:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: How can I dynamically split my sample data using regex or any other options are available?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121407#M32671</link>
      <description>&lt;P&gt;Hopefully  you have a limited chain otherwise an iterative approach like mine won't work.  Let's assume you can have at most 4 in a chain; this should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "(?&amp;lt;TransactionCode&amp;gt;.{3})(?&amp;lt;FieldValueLen&amp;gt;.{2})(?&amp;lt;TempFieldValue&amp;gt;.*)"
| eval FieldValue=substr(TempFieldValue,1,FieldValueLen)
| eval TempFieldValue=substr(TempFieldValue,1+FieldValueLen)
| eval subevent=TransactionCode . ":::" . FieldValueLen . ":::" . FieldValue
| rex "(?&amp;lt;TempTransactionCode&amp;gt;.{3})(?&amp;lt;TempFieldValueLen&amp;gt;.{2})(?&amp;lt;TempFieldValue&amp;gt;.*)"
| eval TransactionCode=mvappend(TransactionCode, TempTransactionCode)
| eval FieldValueLen=mvappend(FieldValueLen, TempFieldValueLen)
| eval FieldValue=mvppend(FieldValue, substr(TempFieldValue,1,TempFieldValueLen)
| eval TempFieldValue=substr(TempFieldValue,1+TempFieldValueLen)
| eval subevent=mvappend(subevent, TempTransactionCode . ":::" . TempFieldValueLen . ":::" . TempFieldValue)
| rex "(?&amp;lt;TempTransactionCode&amp;gt;.{3})(?&amp;lt;TempFieldValueLen&amp;gt;.{2})(?&amp;lt;TempFieldValue&amp;gt;.*)"
| eval TransactionCode=mvappend(TransactionCode, TempTransactionCode)
| eval FieldValueLen=mvappend(FieldValueLen, TempFieldValueLen)
| eval FieldValue=mvppend(FieldValue, substr(TempFieldValue,1,TempFieldValueLen)
| eval TempFieldValue=substr(TempFieldValue,1+TempFieldValueLen)
| eval subevent=mvappend(subevent, TempTransactionCode . ":::" . TempFieldValueLen . ":::" . TempFieldValue)
| rex "(?&amp;lt;TempTransactionCode&amp;gt;.{3})(?&amp;lt;TempFieldValueLen&amp;gt;.{2})(?&amp;lt;TempFieldValue&amp;gt;.*)"
| eval TransactionCode=mvappend(TransactionCode, TempTransactionCode)
| eval FieldValueLen=mvappend(FieldValueLen, TempFieldValueLen)
| eval FieldValue=mvppend(FieldValue, substr(TempFieldValue,1,TempFieldValueLen)
| eval subevent=mvappend(subevent, TempTransactionCode . ":::" . TempFieldValueLen . ":::" . TempFieldValue)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Each event has several new &lt;CODE&gt;multivalued&lt;/CODE&gt; fields and if you need to break out each subevent into a separate event, you add this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| mvexpand subevent | rex field=subevent "(?&amp;lt;TransactionCode&amp;gt;.*?):::(?&amp;lt;FieldValueLen&amp;gt;.*?):::(?&amp;lt;FieldValue&amp;gt;.*)"  | table TransactionCode FieldValueLen FieldValue
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jul 2015 19:00:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121407#M32671</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-07-14T19:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: How can I dynamically split my sample data using regex or any other options are available?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121408#M32672</link>
      <description>&lt;P&gt;Hai Woodcock,&lt;/P&gt;

&lt;P&gt;Thank you very much.&lt;BR /&gt;
I will try it with another sample file.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2015 19:25:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121408#M32672</guid>
      <dc:creator>Shan</dc:creator>
      <dc:date>2015-07-14T19:25:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I dynamically split my sample data using regex or any other options are available?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121409#M32673</link>
      <description>&lt;P&gt;This cannot be currently done. The regular expressions won't ever match properly, and using &lt;CODE&gt;.*&lt;/CODE&gt; gets way to much data to be useful. The only fix here is to edit the source of the data (or perform prior processing with a script) to sed the data correctly.&lt;/P&gt;

&lt;P&gt;Here is a sample &lt;CODE&gt;bash&lt;/CODE&gt; script that will separate out the portions you need.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/bin/bash
data="001021300204053800309123d5-78900404data00503get"
myIndex=0
while [ $myIndex -lt ${#data} ]
do
  txnid=${data:$myIndex:3}
  myIndex=$[$myIndex+3]
  txnlen=`echo ${data:$myIndex:2}|sed 's/^0*//'`
  myIndex=$[$myIndex+2]
  txnstr=${data:$myIndex:$txnlen}
  myIndex=$[$myIndex+$txnlen]
  echo "txnid=$txnid txnlen=$txnlen txnstr=\"$txnstr\" "
done
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This can be setup as a scripted input (passing in the correct values for &lt;CODE&gt;data&lt;/CODE&gt; from command line) or by running it on the logs on the server, placing the output into a new location, and using the forwarder on the new logs with proper parsing. Then this is consumed and search like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your_scripted_input&amp;gt; | table txnid txnlen txnstr
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jul 2015 16:16:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121409#M32673</guid>
      <dc:creator>alacercogitatus</dc:creator>
      <dc:date>2015-07-15T16:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I dynamically split my sample data using regex or any other options are available?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121410#M32674</link>
      <description>&lt;P&gt;Don't forget to "Accept" the answer to close this question.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 16:27:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-dynamically-split-my-sample-data-using-regex-or-any/m-p/121410#M32674</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-07-15T16:27:28Z</dc:date>
    </item>
  </channel>
</rss>

