<?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: Removing line breaks within XML log data in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25362#M4106</link>
    <description>&lt;P&gt;Thanks. The search-time solution appears to work. &lt;BR /&gt;
[although I'm a little confused by the first rex expression &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I think I follow most of it except the first group match (?s)]&lt;/P&gt;</description>
    <pubDate>Sat, 07 Aug 2010 03:28:07 GMT</pubDate>
    <dc:creator>cparham</dc:creator>
    <dc:date>2010-08-07T03:28:07Z</dc:date>
    <item>
      <title>Removing line breaks within XML log data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25359#M4103</link>
      <description>&lt;P&gt;This is related to &lt;A href="http://answers.splunk.com/questions/2141/xml-log-source-type" rel="nofollow"&gt;http://answers.splunk.com/questions/2141/xml-log-source-type&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;How would I remove line breaks found inside elements &lt;CODE&gt;&amp;lt;Sql_Text&amp;gt;...&amp;lt;/Sql_Text&amp;gt;&lt;/CODE&gt;. Many of the SQL statements inside &lt;CODE&gt;&amp;lt;Sql_Text&amp;gt;&lt;/CODE&gt; tags have hard line breaks often at very undesirable places. &lt;/P&gt;

&lt;P&gt;For example:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Sql_Text&amp;gt;UPDATE APP_USR SET CONTACT_ID = 2 WHERE APP_  
ID = 64  
&amp;lt;/Sql_Text&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need it to look like this to make searching possible:  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Sql_Text&amp;gt;  
UPDATE APP_USR SET CONTACT_ID = 2 WHERE APP_ID = 64  
&amp;lt;/Sql_Text&amp;gt;  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or even this  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Sql_Text&amp;gt;UPDATE APP_USR SET CONTACT_ID = 2 WHERE APP_ID = 64&amp;lt;/Sql_Text&amp;gt;  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2010 04:03:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25359#M4103</guid>
      <dc:creator>cparham</dc:creator>
      <dc:date>2010-08-05T04:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Removing line breaks within XML log data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25360#M4104</link>
      <description>&lt;P&gt;Is there a constant-width wrapping going on here?  The problem with completely stripping out end-of-line characters like this is that there could be times where there are legitimate line breaks in the actual SQL statement; so you could end up with values lines being mashed together that shouldn't be.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Aug 2010 21:07:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25360#M4104</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-08-05T21:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Removing line breaks within XML log data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25361#M4105</link>
      <description>&lt;P&gt;I don't think this is possible to do within a single regular expression.  So you'll have to either:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Fix this externally using a scripted input.  (This is the most complicated approach and the only one that will yield correct index-time results.)&lt;/LI&gt;
&lt;LI&gt;Fix your data a search time using a sequence of commands (which could be consolidated using a  macro for simplicity.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Here is a search-time solution that would get reformat your text the way you are looking for:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "(?s)^(?&amp;lt;_sqltxt_pre&amp;gt;.*?&amp;lt;Sql_Text&amp;gt;)(?&amp;lt;Sql_Text&amp;gt;.*?)(?&amp;lt;_sqltxt_post&amp;gt;&amp;lt;/Sql_Text&amp;gt;.*)$" | rex field=Sql_Text mode=sed "s/[\r\n]//g" | eval _raw=_sqltxt_pre . trim(Sql_Text) . _sqltxt_post
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So for your example above, if you want to search for APP_ID 64, then you would need a search like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=oracle_audit_xml | rex "(?s)^(?&amp;lt;_sqltxt_pre&amp;gt;.*?&amp;lt;Sql_Text&amp;gt;)(?&amp;lt;Sql_Text&amp;gt;.*?)(?&amp;lt;_sqltxt_post&amp;gt;&amp;lt;/Sql_Text&amp;gt;.*)$" | rex field=Sql_Text mode=sed "s/[\r\n]//g" | eval _raw=_sqltxt_pre . trim(Sql_Text) . _sqltxt_post | search "APP_ID = 64"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Aug 2010 21:27:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25361#M4105</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-08-05T21:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Removing line breaks within XML log data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25362#M4106</link>
      <description>&lt;P&gt;Thanks. The search-time solution appears to work. &lt;BR /&gt;
[although I'm a little confused by the first rex expression &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I think I follow most of it except the first group match (?s)]&lt;/P&gt;</description>
      <pubDate>Sat, 07 Aug 2010 03:28:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25362#M4106</guid>
      <dc:creator>cparham</dc:creator>
      <dc:date>2010-08-07T03:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Removing line breaks within XML log data</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25363#M4107</link>
      <description>&lt;P&gt;&lt;CODE&gt;(?s)&lt;/CODE&gt; tells the regular expression engine that &lt;CODE&gt;.&lt;/CODE&gt; (dot) can match anything.  (Without this the expression &lt;CODE&gt;.*&lt;/CODE&gt; will not match across the end of a line, which we need in this case since your event spans multiple lines.)  Basically we are breaking each event into 3 pieces, modifying the middle (e.g. your "Sql_Text") and then joining the 3 pieces back into one big event.  I thought I added a basic explanation, but would appearer that I forgot. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;  Sorry about that.  Best of luck!  I recommend &lt;A href="http://www.regular-expressions.info/"&gt;http://www.regular-expressions.info/&lt;/A&gt; for better understanding regular expressions.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Aug 2010 06:37:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Removing-line-breaks-within-XML-log-data/m-p/25363#M4107</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-08-07T06:37:05Z</dc:date>
    </item>
  </channel>
</rss>

