<?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 a field based on other defined fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66541#M16561</link>
    <description>&lt;P&gt;It would help a LOT if you could post a few sample lines of data.&lt;/P&gt;

&lt;P&gt;Anyway, assuming that you have a log format that looks like the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; login=&amp;lt;a username&amp;gt;
 tab
 eventcode=&amp;lt;event code&amp;gt;
 spaces
 some data that you wish to extract
 some more spaces
 status=&amp;lt;success/fail&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;On single lines this would be something like;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;login=JR    eventcode=3   kill all! get oil!  status=success
login=bobby eventcode=8  get nice haircut  status=fail
login=cliff eventcode=4    succeed in business  status=fail
login=sueellen    eventcode=6  have drink (again)  status=success
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can extract whatever is between the eventcode and status fields by the following rex statement. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=your_sourcetype | rex "eventcode=\d+\s+(?&amp;lt;task&amp;gt;.*)\s+status=\w+$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You should now have a field called &lt;CODE&gt;task&lt;/CODE&gt; containing the text between the previously extracted fields.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;Ok, we'll be making a few assumptions anyway:&lt;/P&gt;

&lt;P&gt;after the date/time and some text there will always be parenthesis around a few uppercase letters/words&lt;BR /&gt;
followed by some space&lt;BR /&gt;
followed by 2-5 uppercase letters&lt;BR /&gt;
followed by some space &lt;BR /&gt;
followed by the name we wish to extract. This name can contain uppercase letters, commas and spaces, but not numbers&lt;BR /&gt;
followed by some space&lt;BR /&gt;
followed by a 5-20 digit number&lt;BR /&gt;
followed by some space&lt;BR /&gt;
followed by a 5-20 digit number&lt;/P&gt;

&lt;P&gt;If this is the case, the extraction of NAME would be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "\s+\([A-Z ]+\)\s+[A-Z]{2,5}\s+(?&amp;lt;NAME&amp;gt;[^\d]+)\s+\d{5,20}\s+\d{5,20}"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope this helps,&lt;/P&gt;

&lt;P&gt;kristian&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2012 11:27:44 GMT</pubDate>
    <dc:creator>kristian_kolb</dc:creator>
    <dc:date>2012-02-07T11:27:44Z</dc:date>
    <item>
      <title>How to extract a field based on other defined fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66540#M16560</link>
      <description>&lt;P&gt;Anyone has an idea on how to define a new field based on previously defined fields?  Log format is a bit tricky, delimiters are not the same (some are spaces, some are tabs)&lt;/P&gt;

&lt;P&gt;Example Log:&lt;/P&gt;

&lt;P&gt;field1(tab)field2(spaces)unextracted_data(space)field3&lt;/P&gt;

&lt;P&gt;Objective is to extract "unextracted_data" as any data (excluding white spaces if possible) in between any 2 fields (in this example, field2 and field3).  &lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2012 09:20:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66540#M16560</guid>
      <dc:creator>mcm10285</dc:creator>
      <dc:date>2012-02-07T09:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field based on other defined fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66541#M16561</link>
      <description>&lt;P&gt;It would help a LOT if you could post a few sample lines of data.&lt;/P&gt;

&lt;P&gt;Anyway, assuming that you have a log format that looks like the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; login=&amp;lt;a username&amp;gt;
 tab
 eventcode=&amp;lt;event code&amp;gt;
 spaces
 some data that you wish to extract
 some more spaces
 status=&amp;lt;success/fail&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;On single lines this would be something like;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;login=JR    eventcode=3   kill all! get oil!  status=success
login=bobby eventcode=8  get nice haircut  status=fail
login=cliff eventcode=4    succeed in business  status=fail
login=sueellen    eventcode=6  have drink (again)  status=success
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can extract whatever is between the eventcode and status fields by the following rex statement. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=your_sourcetype | rex "eventcode=\d+\s+(?&amp;lt;task&amp;gt;.*)\s+status=\w+$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You should now have a field called &lt;CODE&gt;task&lt;/CODE&gt; containing the text between the previously extracted fields.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;Ok, we'll be making a few assumptions anyway:&lt;/P&gt;

&lt;P&gt;after the date/time and some text there will always be parenthesis around a few uppercase letters/words&lt;BR /&gt;
followed by some space&lt;BR /&gt;
followed by 2-5 uppercase letters&lt;BR /&gt;
followed by some space &lt;BR /&gt;
followed by the name we wish to extract. This name can contain uppercase letters, commas and spaces, but not numbers&lt;BR /&gt;
followed by some space&lt;BR /&gt;
followed by a 5-20 digit number&lt;BR /&gt;
followed by some space&lt;BR /&gt;
followed by a 5-20 digit number&lt;/P&gt;

&lt;P&gt;If this is the case, the extraction of NAME would be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "\s+\([A-Z ]+\)\s+[A-Z]{2,5}\s+(?&amp;lt;NAME&amp;gt;[^\d]+)\s+\d{5,20}\s+\d{5,20}"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;hope this helps,&lt;/P&gt;

&lt;P&gt;kristian&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2012 11:27:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66541#M16561</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-02-07T11:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field based on other defined fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66542#M16562</link>
      <description>&lt;P&gt;Your idea is almost there, however, your example log is different.  What I meant by previously defined fields are fields that were extracted thru "Field Extraction" of SearchHead (manually defined).  Below is a sample of logs.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;1/31/2012 23:51&lt;/STRONG&gt; &lt;STRONG&gt;4 NCR (NEW AREAS)&lt;/STRONG&gt;   &lt;STRONG&gt;VB&lt;/STRONG&gt;  &lt;EM&gt;CRUZ, MODESTO FERDINAND&lt;/EM&gt;   &lt;STRONG&gt;27488123&lt;/STRONG&gt;    9795322 PL  TIMBER - NTF    MNL704-M    MNL704-M    FCR012 NO BROWSING  COM 02/01/2012 21:33:45 FXR039 NO TROUBLE FOUND - VISITED   FNR095 NO TROUBLE FOUND -VISITED    COM-zptit609-1202-4098        VISATECH/COMBO/1PM/NTF FOR TERMINATION OF ACCOUNT/TALKED TO SUBS/CTC#09175704996/Uncontact    Manila 2    VISATECH    LUZON   GMA 2&lt;/P&gt;

&lt;P&gt;Those in bold were extracted using the "Field Extractor" and the one in Italics is not yet defined.  Hope this clarifies it further and hope you can help further as well, thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2012 00:00:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66542#M16562</guid>
      <dc:creator>mcm10285</dc:creator>
      <dc:date>2012-02-08T00:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field based on other defined fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66543#M16563</link>
      <description>&lt;P&gt;I can help you quite easily with this particular event, but in order for this to work for sure, I'd need to know more about the actual format.&lt;/P&gt;

&lt;P&gt;first there is date and time. fine.&lt;BR /&gt;
then a number (always present, always number?) &lt;BR /&gt;
then a three letter code (always present, always three, always letters?)&lt;BR /&gt;
then something in parentheses. (always present, always within parentheses?)&lt;BR /&gt;
then a two letter code (always two, always letters, always present?)&lt;BR /&gt;
then a name(?) (always lastname, firstname(s)?)&lt;BR /&gt;
then a number (8 digits), always eight? always present?&lt;/P&gt;

&lt;P&gt;Where are the tabs?&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2012 07:05:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66543#M16563</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-02-08T07:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field based on other defined fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66544#M16564</link>
      <description>&lt;P&gt;Please see answers to your queries below&lt;/P&gt;

&lt;P&gt;first there is date and time. fine.&lt;BR /&gt;
then a three letter code (always present, always three, always letters?) &lt;/P&gt;

&lt;P&gt;then something in parentheses. (always present, always within parentheses?)&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;"4 NCR (NEW AREAS)" is one field&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;then a two letter code (always two, always letters, always present?)&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Could be up to 5 letters&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;then a name(?) (always lastname, firstname(s)?)&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Could be one name only, some contain "comma" at the end&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;then a number (8 digits), always eight? always present?&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Could be more than 8 numbers, it is a reference number that increases&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;Where are the tabs?&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;may not be tabs, can be a number of spaces....&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 08 Feb 2012 09:34:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66544#M16564</guid>
      <dc:creator>mcm10285</dc:creator>
      <dc:date>2012-02-08T09:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field based on other defined fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66545#M16565</link>
      <description>&lt;P&gt;Great! Worked Like a charm! have to exercise myself on the regex.  Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2012 10:18:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66545#M16565</guid>
      <dc:creator>mcm10285</dc:creator>
      <dc:date>2012-02-08T10:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a field based on other defined fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66546#M16566</link>
      <description>&lt;P&gt;Glad it helped - please mark the question as 'answered' a/o upvote.&lt;/P&gt;

&lt;P&gt;/k&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2012 10:22:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-based-on-other-defined-fields/m-p/66546#M16566</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-02-08T10:22:43Z</dc:date>
    </item>
  </channel>
</rss>

