<?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 How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145207#M40443</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I am filtering some logs came from Nessus in order to identify vulnerable machines based on their OS, and the issue I have is when a host's OS is not adequately identified resulting in many "os" fields. An example is the below:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;start_time="Mon Feb 16 03:56:07 2015"&lt;BR /&gt;
end_time="Mon Feb 16 03:57:42 2015" &lt;BR /&gt;
&lt;STRONG&gt;os="Microsoft Windows 2000"&lt;/STRONG&gt; &lt;STRONG&gt;os="Microsoft Windows XP for Embedded Systems"&lt;/STRONG&gt; &lt;STRONG&gt;os="Microsoft&lt;BR /&gt;
Windows XP"&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The query that I created for that (which only works sufficiently when 1 OS is found) is the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational  | rex "start_time=\"(?&amp;lt;start&amp;gt;.*)\"\send.*\s\sos=\"(?&amp;lt;OS&amp;gt;.*)\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I would like ideally to do, is to just find a way to filter out the " (double quote" symbol from within the extracted field. This is because apart from Windows machines, there are other printers and access points that are interpreted as many other mixed OSs.&lt;/P&gt;

&lt;P&gt;So, it should be something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational  | rex "start_time=\"(?&amp;lt;start&amp;gt;.*)\"\send.*\s\sos=\"(?&amp;lt;OS&amp;gt;.*[^\"])\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but it doesn't work.&lt;/P&gt;

&lt;P&gt;Any thoughts?&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Evang&lt;/P&gt;

&lt;P&gt;Update:&lt;/P&gt;

&lt;P&gt;Hi MuS,&lt;/P&gt;

&lt;P&gt;Okay, here we are.&lt;/P&gt;

&lt;P&gt;I guess I haven't stated my problem correctly. &lt;STRONG&gt;I do not want to remove the double quotes, actually, I want to only keep the first occurence of OS field in the rare cases that more than one appears!&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Here is what I managed to do with sed, but I am not there quite yet.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational earliest=-5w@w1 latest=now|rex field=os mode=sed "s/.*\(os=\"[^\"]*\"\).*$/\1/g" | rex ".*os=\"(?P&amp;lt;OS&amp;gt;.*)\"\s.*\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any suggestions? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Evang&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 18:57:58 GMT</pubDate>
    <dc:creator>evang_26</dc:creator>
    <dc:date>2020-09-28T18:57:58Z</dc:date>
    <item>
      <title>How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145207#M40443</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I am filtering some logs came from Nessus in order to identify vulnerable machines based on their OS, and the issue I have is when a host's OS is not adequately identified resulting in many "os" fields. An example is the below:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;start_time="Mon Feb 16 03:56:07 2015"&lt;BR /&gt;
end_time="Mon Feb 16 03:57:42 2015" &lt;BR /&gt;
&lt;STRONG&gt;os="Microsoft Windows 2000"&lt;/STRONG&gt; &lt;STRONG&gt;os="Microsoft Windows XP for Embedded Systems"&lt;/STRONG&gt; &lt;STRONG&gt;os="Microsoft&lt;BR /&gt;
Windows XP"&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The query that I created for that (which only works sufficiently when 1 OS is found) is the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational  | rex "start_time=\"(?&amp;lt;start&amp;gt;.*)\"\send.*\s\sos=\"(?&amp;lt;OS&amp;gt;.*)\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I would like ideally to do, is to just find a way to filter out the " (double quote" symbol from within the extracted field. This is because apart from Windows machines, there are other printers and access points that are interpreted as many other mixed OSs.&lt;/P&gt;

&lt;P&gt;So, it should be something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational  | rex "start_time=\"(?&amp;lt;start&amp;gt;.*)\"\send.*\s\sos=\"(?&amp;lt;OS&amp;gt;.*[^\"])\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but it doesn't work.&lt;/P&gt;

&lt;P&gt;Any thoughts?&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Evang&lt;/P&gt;

&lt;P&gt;Update:&lt;/P&gt;

&lt;P&gt;Hi MuS,&lt;/P&gt;

&lt;P&gt;Okay, here we are.&lt;/P&gt;

&lt;P&gt;I guess I haven't stated my problem correctly. &lt;STRONG&gt;I do not want to remove the double quotes, actually, I want to only keep the first occurence of OS field in the rare cases that more than one appears!&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Here is what I managed to do with sed, but I am not there quite yet.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational earliest=-5w@w1 latest=now|rex field=os mode=sed "s/.*\(os=\"[^\"]*\"\).*$/\1/g" | rex ".*os=\"(?P&amp;lt;OS&amp;gt;.*)\"\s.*\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any suggestions? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Evang&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:57:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145207#M40443</guid>
      <dc:creator>evang_26</dc:creator>
      <dc:date>2020-09-28T18:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145208#M40444</link>
      <description>&lt;P&gt;You were &lt;EM&gt;so&lt;/EM&gt; close.  Try this.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "start_time=\"(?P&amp;lt;start&amp;gt;.*)\"\send.*\sos=\"(?P&amp;lt;OS&amp;gt;[^\"]*?)\""
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Feb 2015 18:17:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145208#M40444</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-02-16T18:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145209#M40445</link>
      <description>&lt;P&gt;Hi evang_26,&lt;/P&gt;

&lt;P&gt;Okay after reading the update, it makes sense, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational  | rex max_match=1 "start_time=\"(?&amp;lt;start&amp;gt;.*)\"\send.*\s\sos=\"(?&amp;lt;OS&amp;gt;[\w+\s]+)\"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will match only one occurrence for each field in the regex&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 16 Feb 2015 18:19:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145209#M40445</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-02-16T18:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145210#M40446</link>
      <description>&lt;P&gt;Can you add an example of how you would like the output to look like?&lt;BR /&gt;
The solution provided by MuS would give you the output without any double quotes, but its not really clear if thats what your intention is or if you would like to create a multivalue field with all the different OS's added.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2015 00:05:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145210#M40446</guid>
      <dc:creator>ramdaspr</dc:creator>
      <dc:date>2015-02-17T00:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145211#M40447</link>
      <description>&lt;P&gt;Hi richgallowway,&lt;/P&gt;

&lt;P&gt;I already tried this, placing the [] in front and on the end, no luck.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Evang&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2015 10:58:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145211#M40447</guid>
      <dc:creator>evang_26</dc:creator>
      <dc:date>2015-02-17T10:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145212#M40448</link>
      <description>&lt;P&gt;Hi MuS,&lt;/P&gt;

&lt;P&gt;Okay, here we are.&lt;/P&gt;

&lt;P&gt;I guess I haven't stated my problem correctly. &lt;STRONG&gt;I do not want to remove the double quotes, actually, I want to only keep the first occurence of OS field in the rare cases that more than one appears!&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Here is what I managed to do with sed, but I am not there quite yet.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational earliest=-5w@w1 latest=now|rex field=os mode=sed "s/.*\(os=\"[^\"]*\"\).*$/\1/g" | rex ".*os=\"(?P&amp;lt;OS&amp;gt;.*)\"\s.*\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any suggestions? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Evang&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2015 11:14:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145212#M40448</guid>
      <dc:creator>evang_26</dc:creator>
      <dc:date>2015-02-17T11:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145213#M40449</link>
      <description>&lt;P&gt;Hi ramdaspr,&lt;/P&gt;

&lt;P&gt;To be honest, as I stated on MuS's answer, my problem wasn't sufficiently clarified. I want to keep just the first occurrence of OS field in case there are more than one. This way, the dashboard want look overwhelmed by huge tags,  will look prettier and in fact, Nessus orders OS guesses based on  probability.&lt;/P&gt;

&lt;P&gt;Look below MuS's answer my comment and my attempt.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Evang&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2015 11:17:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145213#M40449</guid>
      <dc:creator>evang_26</dc:creator>
      <dc:date>2015-02-17T11:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145214#M40450</link>
      <description>&lt;P&gt;Okay, now it makes sense, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=nessus severity!=informational  | rex max_match=1 "start_time=\"(?&amp;lt;start&amp;gt;.*)\"\send.*\s\sos=\"(?&amp;lt;OS&amp;gt;[\w+\s]+)\"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will match only one occurrence for each field in the regex&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2015 11:26:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145214#M40450</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-02-17T11:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145215#M40451</link>
      <description>&lt;P&gt;Hi MuS,&lt;/P&gt;

&lt;P&gt;It worked perfectly!&lt;/P&gt;

&lt;P&gt;Thanks you very much!&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Evang&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2015 12:23:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145215#M40451</guid>
      <dc:creator>evang_26</dc:creator>
      <dc:date>2015-02-17T12:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract just one field from a log when there are multiple that carry the same attribute name? - Regular Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145216#M40452</link>
      <description>&lt;P&gt;you're welcome, I've updated your question and my answer so it makes sense &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Feb 2015 12:35:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-just-one-field-from-a-log-when-there-are-multiple/m-p/145216#M40452</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-02-17T12:35:05Z</dc:date>
    </item>
  </channel>
</rss>

