<?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 two fields from a group in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639791#M221706</link>
    <description>&lt;P&gt;If I just want the IP address and not the COSID, what do I cut out?&amp;nbsp; Turns out COSID isn't always there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 14:30:55 GMT</pubDate>
    <dc:creator>kmhanson</dc:creator>
    <dc:date>2023-04-13T14:30:55Z</dc:date>
    <item>
      <title>How to extract two fields from a group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639774#M221702</link>
      <description>&lt;P&gt;I am new to Regex expressions and trying to figure them out.&lt;/P&gt;
&lt;P&gt;I am trying to extract two sections of the following log field:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5002:fromhost=999.99.99.99:fromport=3299:sid=92ac3498-d95d-11ed-af19-92eb6037d638:respcode=OK:resptime=7:node=999999ss03:nodePort=5002:cosId=asasasa&lt;/P&gt;
&lt;P&gt;I want the IP address that shows after fromhost and the COSID value asasasa at the end of the field and not having much luck&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 15:52:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639774#M221702</guid>
      <dc:creator>kmhanson</dc:creator>
      <dc:date>2023-04-13T15:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639781#M221703</link>
      <description>&lt;P&gt;fromhost=(?&amp;lt;fromhost&amp;gt;[^:]+).*cosId=(?&amp;lt;cosid&amp;gt;.*)&lt;/P&gt;&lt;P&gt;&lt;A href="https://regex101.com/r/rZq5Gn/1" target="_blank"&gt;https://regex101.com/r/rZq5Gn/1&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 13:40:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639781#M221703</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-04-13T13:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639791#M221706</link>
      <description>&lt;P&gt;If I just want the IP address and not the COSID, what do I cut out?&amp;nbsp; Turns out COSID isn't always there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:30:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639791#M221706</guid>
      <dc:creator>kmhanson</dc:creator>
      <dc:date>2023-04-13T14:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639793#M221707</link>
      <description>&lt;P&gt;Use two separate expressions&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;fromhost=(?&amp;lt;fromhost&amp;gt;[^:]+)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;cosId=(?&amp;lt;cosid&amp;gt;.*)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;That way, you will get the field if the anchor matches, and it will be null if the anchor isn't found&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:35:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639793#M221707</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-04-13T14:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639794#M221708</link>
      <description>&lt;P&gt;That is very elegant solution by&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;here. Depending on how many logs you have and how far you go with your REGEX learning you might want to start doing a bit more defined groups too e.g.:&lt;BR /&gt;fromhost=(?&amp;lt;fromhost&amp;gt;\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*cosId=(?&amp;lt;cosid&amp;gt;[^\s]+)&lt;/P&gt;&lt;P&gt;Which now looks for exact pattern of the IP address. Or something more convoluted but doing same thing:&lt;BR /&gt;fromhost=(?&amp;lt;fromhost&amp;gt;(\d{1,3}(\.)?){4}).+cosId=(?&amp;lt;cosid&amp;gt;[^\s]+)&lt;BR /&gt;&lt;BR /&gt;Where numbers placed in curly brackets tell you how much the preceding pattern would repeat:&lt;BR /&gt;e.g {1,3} from one to 3 times. As in \d{1,3} means any digit one or three times like in the IP address.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Why things like that important? Is because the more you start work with Splunk and the more events you parse that way. The more patterns of .* might start to impact you and hogging your CPU. Seen too many issues when the patterns start to go out of control.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Good luck and welcome to the wonderful world of Regular Expressions.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:38:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639794#M221708</guid>
      <dc:creator>dtsariapkin</dc:creator>
      <dc:date>2023-04-13T14:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639796#M221709</link>
      <description>&lt;P&gt;so is the full command: | rex field=port mode=sed fromhost=(?&amp;lt;fromhost&amp;gt;[^:]+)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:39:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639796#M221709</guid>
      <dc:creator>kmhanson</dc:creator>
      <dc:date>2023-04-13T14:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639798#M221711</link>
      <description>&lt;P&gt;No - mode=sed is for stream editing, which is not required when you are just extracting fields, and assuming you have already extract the port field holding all this information (which was clear from your original post)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=port "fromhost=(?&amp;lt;fromhost&amp;gt;[^:]+)"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:44:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639798#M221711</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-04-13T14:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639799#M221712</link>
      <description>&lt;P&gt;I have hundreds of thousands of logs. I can put it in excel but would rather get it done in sprint so the rest of the team can run the same command.&amp;nbsp; It is more important to get that ip address, the COSID isn't so important&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:44:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639799#M221712</guid>
      <dc:creator>kmhanson</dc:creator>
      <dc:date>2023-04-13T14:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639800#M221713</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/252129"&gt;@kmhanson&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;1) If you adamant in doing it all in single expression. You can do it like that:&lt;BR /&gt;fromhost=(?&amp;lt;fromhost&amp;gt;[^:]+)(.*cosId=(?&amp;lt;cosid&amp;gt;.*))?&lt;BR /&gt;&lt;BR /&gt;Notice I put second part in brackets and put question mark at the end. That means that whatever is in parenthesis before can match once or not match at all.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;2) stick with the basic mode first. SED is for replacing things.&lt;BR /&gt;3) And you do not want field port do you? Not sure it does not exactly state that. Or I am being stupid.&amp;nbsp;&lt;BR /&gt;4) So I would assume you will be extracting from RAW log -&amp;gt; Original log.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;And your final test search would be:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=_raw "fromhost=(?&amp;lt;fromhost&amp;gt;[^:]+)" | rex field=_raw "cosId=(?&amp;lt;cosid&amp;gt;.*)" &lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;OR!&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=_raw "fromhost=(?&amp;lt;fromhost&amp;gt;[^:]+)(.*cosId=(?&amp;lt;cosid&amp;gt;.*))?" &lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;All in all in this command you say from which field you want to extract. "_raw" gives you the whole event. And then you place Regular expression inside the quotes.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If you find any of the solutions good. Do not forget to mark it as answered/solved.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 15:06:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639800#M221713</guid>
      <dc:creator>dtsariapkin</dc:creator>
      <dc:date>2023-04-13T15:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639802#M221714</link>
      <description>&lt;P&gt;rex field=user mode=sed and then the expression?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:52:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639802#M221714</guid>
      <dc:creator>kmhanson</dc:creator>
      <dc:date>2023-04-13T14:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639803#M221715</link>
      <description>&lt;P&gt;&lt;SPAN&gt;No - mode=sed is for stream editing, which is not required when you are just extracting fields&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:54:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639803#M221715</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-04-13T14:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639920#M221743</link>
      <description>&lt;P&gt;Is there any reason why you must use regex? &amp;nbsp;For rigidly formatted strings like this, the easiest - in fact the cheapest solution is kv aka &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Extract" target="_blank" rel="noopener"&gt;extract&lt;/A&gt;. &amp;nbsp;Assuming your field name is log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename _raw as temp, log as _raw
| kv pairdelim=":" kvdelim="="
| rename _raw as log, temp as _raw&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your sample data should give you&lt;/P&gt;&lt;TABLE width="792px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="69px"&gt;cosId&lt;/TD&gt;&lt;TD width="107px"&gt;fromhost&lt;/TD&gt;&lt;TD width="76px"&gt;fromport&lt;/TD&gt;&lt;TD width="103.328125px"&gt;node&lt;/TD&gt;&lt;TD width="50px"&gt;nodePort&lt;/TD&gt;&lt;TD width="49.9375px"&gt;respcode&lt;/TD&gt;&lt;TD width="48.9375px"&gt;resptime&lt;/TD&gt;&lt;TD width="286.828125px"&gt;sid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="69px"&gt;asasasa&lt;/TD&gt;&lt;TD width="107px"&gt;999.99.99.99&lt;/TD&gt;&lt;TD width="76px"&gt;3299&lt;/TD&gt;&lt;TD width="103.328125px"&gt;999999ss03&lt;/TD&gt;&lt;TD width="50px"&gt;5002&lt;/TD&gt;&lt;TD width="49.9375px"&gt;OK&lt;/TD&gt;&lt;TD width="48.9375px"&gt;7&lt;/TD&gt;&lt;TD width="286.828125px"&gt;92ac3498-d95d-11ed-af19-92eb6037d638&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 07:34:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639920#M221743</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-04-14T07:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639982#M221766</link>
      <description>&lt;P&gt;Install the TA.&amp;nbsp; It will do all of this.&lt;/P&gt;&lt;P&gt;Otherwise you can do this:&lt;BR /&gt;... | rex "fromhost=(?&amp;lt;fromhost&amp;gt;[^=:]+).*:cosId=(?&amp;lt;cosId&amp;gt;.*)$"&lt;/P&gt;&lt;P&gt;But it would be better to setup a sourcetype-based global extraction (which the TA surely does), like this:&lt;BR /&gt;(?&amp;lt;_KEY_1&amp;gt;[^=:]+)=(?&amp;lt;_VAL_1&amp;gt;[^=:]+)&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 18:29:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/639982#M221766</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2023-04-14T18:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/640193#M221840</link>
      <description>&lt;P&gt;I did play and get it to work.&amp;nbsp; A big help. Thanks so much to both of you for the help.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 11:35:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/640193#M221840</guid>
      <dc:creator>kmhanson</dc:creator>
      <dc:date>2023-04-17T11:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract two fields from a group</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/640194#M221841</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/252129"&gt;@kmhanson&lt;/a&gt;&amp;nbsp;Good to know. Don't forget to mark the answer as solution. And give people who helped Karma. That keeps them going!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 11:41:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-two-fields-from-a-group/m-p/640194#M221841</guid>
      <dc:creator>dtsariapkin</dc:creator>
      <dc:date>2023-04-17T11:41:14Z</dc:date>
    </item>
  </channel>
</rss>

