<?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: Help with SEDCMD in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541086#M90553</link>
    <description>&lt;P&gt;To keep everything up to and including {host n.n.n.n}, try:&lt;/P&gt;&lt;P&gt;"s/(.*{host \d+\.\d+\.\d+\.\d+}).*/\1/g"&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2021 20:57:25 GMT</pubDate>
    <dc:creator>tscroggins</dc:creator>
    <dc:date>2021-02-23T20:57:25Z</dc:date>
    <item>
      <title>Help with SEDCMD</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541049#M90548</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have done my due diligence scouring internet forums and docs but can't seem to figure out how to tailor this sedcmd I'm using in this query to remove everything after host. This log is from a mainframe system and is broken in a funky manner. I am wanting to keep the host entry that is bolded but remove everything after this. Can I get someone to assist me with the sedcmd and explain how to apply this "wildcard" to everything in the log not just the line in question?&lt;/P&gt;&lt;P&gt;Log:&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t h"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.469604&lt;/SPAN&gt; &lt;SPAN class="t"&gt;host-qa&lt;/SPAN&gt; &lt;SPAN class="t"&gt;log&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;start&lt;/SPAN&gt; &lt;SPAN class="t"&gt;1614098751.47494&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;addr&lt;/SPAN&gt;&amp;nbsp;xx,xx&lt;SPAN class="t"&gt;.xx.194&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;port&lt;/SPAN&gt; &lt;SPAN class="t"&gt;85488&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;method&lt;/SPAN&gt; &lt;SPAN class="t"&gt;GET&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;url&lt;/SPAN&gt; &lt;SPAN class="t"&gt;/statictest.html&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;bytes&lt;/SPAN&gt; &lt;SPAN class="t"&gt;399&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;status&lt;/SPAN&gt; &lt;SPAN class="t"&gt;200&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;end&lt;/SPAN&gt; &lt;SPAN class="t"&gt;1614098751.461997&lt;/SPAN&gt;&lt;SPAN&gt;} &lt;STRONG&gt;{&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class="t"&gt;host&lt;/SPAN&gt;&amp;nbsp;88&lt;SPAN class="t"&gt;.10.30.7&lt;/SPAN&gt;} &lt;/STRONG&gt;&lt;SPAN class="t"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.469604&lt;/SPAN&gt; &lt;SPAN class="t"&gt;nstop-qa&lt;/SPAN&gt; &lt;SPAN class="t"&gt;CommonLog:&lt;/SPAN&gt; &lt;SPAN class="t"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.469604&lt;/SPAN&gt; &lt;SPAN class="t"&gt;nstop-qa&lt;/SPAN&gt; &lt;SPAN class="t"&gt;10.13.80.7&lt;/SPAN&gt; &lt;SPAN class="t"&gt;-&lt;/SPAN&gt; &lt;SPAN class="t"&gt;-&lt;/SPAN&gt;&lt;SPAN&gt; [&lt;/SPAN&gt;&lt;SPAN class="t"&gt;23/Feb/2021:11:45:51&lt;/SPAN&gt; &lt;SPAN class="t"&gt;-0500&lt;/SPAN&gt;&lt;SPAN&gt;] "&lt;/SPAN&gt;&lt;SPAN class="t"&gt;GET&lt;/SPAN&gt; &lt;SPAN class="t"&gt;/statictest.html&lt;/SPAN&gt; &lt;SPAN class="t"&gt;HTTP/1.0&lt;/SPAN&gt;&lt;SPAN&gt;" &lt;/SPAN&gt;&lt;SPAN class="t"&gt;200&lt;/SPAN&gt; &lt;SPAN class="t"&gt;399&lt;/SPAN&gt; &lt;SPAN class="t"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.470248&lt;/SPAN&gt; &lt;SPAN class="t"&gt;host-qa&lt;/SPAN&gt;&lt;SPAN&gt; '&amp;#17; &lt;/SPAN&gt;&lt;SPAN class="t"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.470248&lt;/SPAN&gt; &lt;SPAN class="t"&gt;host-qa&lt;/SPAN&gt;&lt;SPAN&gt; &amp;#1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Query:&lt;/P&gt;&lt;P&gt;basesearch&lt;/P&gt;&lt;P&gt;| rex mode=sed field=_raw "s/{host.*//g"&lt;/P&gt;&lt;P&gt;Results after I run this query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="t h"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.469604&lt;/SPAN&gt; &lt;SPAN class="t"&gt;host-qa&lt;/SPAN&gt; &lt;SPAN class="t"&gt;log&lt;/SPAN&gt;&lt;SPAN&gt; {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;start&lt;/SPAN&gt; &lt;SPAN class="t"&gt;1614098751.47494&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;addr&lt;/SPAN&gt;&amp;nbsp;xx,xx&lt;SPAN class="t"&gt;.xx.194&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;port&lt;/SPAN&gt; &lt;SPAN class="t"&gt;85488&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;method&lt;/SPAN&gt; &lt;SPAN class="t"&gt;GET&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;url&lt;/SPAN&gt; &lt;SPAN class="t"&gt;/statictest.html&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;bytes&lt;/SPAN&gt; &lt;SPAN class="t"&gt;399&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;status&lt;/SPAN&gt; &lt;SPAN class="t"&gt;200&lt;/SPAN&gt;&lt;SPAN&gt;} {&lt;/SPAN&gt;&lt;SPAN class="t"&gt;end&lt;/SPAN&gt; &lt;SPAN class="t"&gt;1614098751.461997&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN class="t"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.469604&lt;/SPAN&gt; &lt;SPAN class="t"&gt;nstop-qa&lt;/SPAN&gt; &lt;SPAN class="t"&gt;CommonLog:&lt;/SPAN&gt; &lt;SPAN class="t"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.469604&lt;/SPAN&gt; &lt;SPAN class="t"&gt;nstop-qa&lt;/SPAN&gt; &lt;SPAN class="t"&gt;10.13.80.7&lt;/SPAN&gt; &lt;SPAN class="t"&gt;-&lt;/SPAN&gt; &lt;SPAN class="t"&gt;-&lt;/SPAN&gt;&lt;SPAN&gt; [&lt;/SPAN&gt;&lt;SPAN class="t"&gt;23/Feb/2021:11:45:51&lt;/SPAN&gt; &lt;SPAN class="t"&gt;-0500&lt;/SPAN&gt;&lt;SPAN&gt;] "&lt;/SPAN&gt;&lt;SPAN class="t"&gt;GET&lt;/SPAN&gt; &lt;SPAN class="t"&gt;/statictest.html&lt;/SPAN&gt; &lt;SPAN class="t"&gt;HTTP/1.0&lt;/SPAN&gt;&lt;SPAN&gt;" &lt;/SPAN&gt;&lt;SPAN class="t"&gt;200&lt;/SPAN&gt; &lt;SPAN class="t"&gt;399&lt;/SPAN&gt; &lt;SPAN class="t"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.470248&lt;/SPAN&gt; &lt;SPAN class="t"&gt;host-qa&lt;/SPAN&gt;&lt;SPAN&gt; '&amp;#17; &lt;/SPAN&gt;&lt;SPAN class="t"&gt;Feb&lt;/SPAN&gt; &lt;SPAN class="t"&gt;23&lt;/SPAN&gt; &lt;SPAN class="t"&gt;11:45:51.470248&lt;/SPAN&gt; &lt;SPAN class="t"&gt;host-qa&lt;/SPAN&gt;&lt;SPAN&gt; &amp;#1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 16:58:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541049#M90548</guid>
      <dc:creator>dfurtaw</dc:creator>
      <dc:date>2021-02-23T16:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help with SEDCMD</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541082#M90551</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;can you try&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex mode=sed field=_raw "s/\{host.*//g"&lt;/LI-CODE&gt;&lt;P&gt;or if that didn’t help then try two \\ before {&lt;BR /&gt;r. Ismo&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 20:48:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541082#M90551</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2021-02-23T20:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help with SEDCMD</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541086#M90553</link>
      <description>&lt;P&gt;To keep everything up to and including {host n.n.n.n}, try:&lt;/P&gt;&lt;P&gt;"s/(.*{host \d+\.\d+\.\d+\.\d+}).*/\1/g"&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 20:57:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541086#M90553</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2021-02-23T20:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with SEDCMD</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541093#M90555</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.splunk.com/t5/user/viewprofilepage/user-id/34962" target="_self"&gt;&lt;SPAN class=""&gt;dfurtaw&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In order to fulfill your requested action you would do the following (&lt;EM&gt;eval&lt;/EM&gt; and &lt;EM&gt;makeresults&lt;/EM&gt; are not necessary, only as an example):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="Feb 23 11:45:51.469604 host-qa log {start 1614098751.47494} {addr xx,xx.xx.194} {port 85488} {method GET} {url /statictest.html} {bytes 399} {status 200} {end 1614098751.461997} {host 88.10.30.7} Feb 23 11:45:51.469604 nstop-qa CommonLog: Feb 23 11:45:51.469604 nstop-qa 10.13.80.7 - - [23/Feb/2021:11:45:51 -0500] \"GET /statictest.html HTTP/1.0\" 200 399 Feb 23 11:45:51.470248 host-qa ' Feb 23 11:45:51.470248 host-qa" 
| rex mode=sed field=_raw "s/.*({host\s(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)}).*/\1/g"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;What are we doing here?&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;BR /&gt;mode=sed&lt;/STRONG&gt; -&amp;gt; Run &lt;A href="https://docs.splunk.com/Documentation/Splunk/8.1.2/SearchReference/Rex#4._Use_a_sed_expression" target="_blank" rel="noopener"&gt;rex command&lt;/A&gt; using stream editor mode.&lt;BR /&gt;-&amp;gt; nice SED documentation(gnu SED): &lt;A href="https://www.gnu.org/software/sed/manual/sed.html" target="_blank" rel="noopener"&gt;https://www.gnu.org/software/sed/manual/sed.html&lt;/A&gt;&lt;BR /&gt;&lt;STRONG&gt;field=_raw &lt;/STRONG&gt;-&amp;gt; Run the following sed command on the _raw field of the event.&lt;BR /&gt;&lt;STRONG&gt;"s/.*({host\s(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)}).*/\1/g"&lt;BR /&gt;&lt;/STRONG&gt;First thing we set sed command &lt;STRONG&gt;s&lt;/STRONG&gt; for substitution. That way everything we match gets replaced with the second part of the expression.&lt;BR /&gt;&lt;BR /&gt;In your case we match everything before and after host in order to discard it.&lt;BR /&gt;See: &lt;STRONG&gt;.*&lt;BR /&gt;&lt;/STRONG&gt;next up&amp;nbsp;&lt;STRONG&gt;({host\s(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)})&lt;/STRONG&gt;&lt;BR /&gt;this is the capture group "()" to match the curly brackets including "host" a space-character and a valid IP address:&lt;BR /&gt;&lt;STRONG&gt;(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} -&amp;gt; &lt;/STRONG&gt;3 first octets like "169."&lt;STRONG&gt;&lt;BR /&gt;(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) &lt;/STRONG&gt;-&amp;gt; last octet of ip address&lt;BR /&gt;&lt;BR /&gt;What is &lt;STRONG&gt;(:?&amp;nbsp; &lt;/STRONG&gt;?&lt;BR /&gt;The notation of colon question mark&amp;nbsp; disables the capturing of the group. This is important i order for the replacement to take the right group.&lt;BR /&gt;&lt;BR /&gt;Each capturing group is silently assigned an index. We can then use that index for the replacement.&lt;BR /&gt;Third part of the expression:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/\1/g &lt;/STRONG&gt;-&amp;gt; Replace with the captured match index \1 globally "g".&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Conclusion 1&lt;/STRONG&gt;:&lt;BR /&gt;Match everything and put the important stuff into a capturing group and use the reference to replace everything&amp;nbsp; with the desired capturing group.&lt;BR /&gt;------------------------&lt;BR /&gt;Now. If you only care for the actual ip occurring at the time. You could also extract the host field. That way you can use _raw for other queries.&lt;BR /&gt;Matching could be similar to the previous example we just don't have to match everything:&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="Feb 23 11:45:51.469604 host-qa log {start 1614098751.47494} {addr xx,xx.xx.194} {port 85488} {method GET} {url /statictest.html} {bytes 399} {status 200} {end 1614098751.461997} {host 88.10.30.7} Feb 23 11:45:51.469604 nstop-qa CommonLog: Feb 23 11:45:51.469604 nstop-qa 10.13.80.7 - - [23/Feb/2021:11:45:51 -0500] \"GET /statictest.html HTTP/1.0\" 200 399 Feb 23 11:45:51.470248 host-qa ' Feb 23 11:45:51.470248 host-qa" 
| rex field=_raw "{host\s(?&amp;lt;host&amp;gt;(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))}"
| timechart count by host&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;You we are now only capturing the ip address, since { host is outside of the capturing group.&lt;BR /&gt;Additionally &lt;STRONG&gt;(?&amp;lt;host&amp;gt;&amp;nbsp;&lt;/STRONG&gt;indicates a named capturing group overwriting the existing host field with the captured value (the IP in this case).&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Conclusion 2:&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;Named capturing groups can help creating new fields to work with down the stream.&lt;BR /&gt;For more help with regex and easier testing I highly recommend &lt;A href="https://regex101.com/" target="_self"&gt;regex101.com&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;If you found this posting helpful please mark as solution and upvote.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 22:14:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Help-with-SEDCMD/m-p/541093#M90555</guid>
      <dc:creator>effem2</dc:creator>
      <dc:date>2021-02-23T22:14:05Z</dc:date>
    </item>
  </channel>
</rss>

