<?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: Fixed-width field extraction but removing trailing spaces in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96698#M25015</link>
    <description>&lt;P&gt;Why not just use a [^\s]+ to capture everything up until a space character? you can then use a \s+ to move ahead to the start of the next character set.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jul 2012 13:05:17 GMT</pubDate>
    <dc:creator>Drainy</dc:creator>
    <dc:date>2012-07-12T13:05:17Z</dc:date>
    <item>
      <title>Fixed-width field extraction but removing trailing spaces</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96697#M25014</link>
      <description>&lt;P&gt;I am currently defining some sourcetypes for some db2 SMF logs (oh joy). Luckily, the fields are well defined and are fixed length, so extracting the values at the correct boundaries is not an issue. As an example, using this regex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex "(?m)^0(?&amp;lt;primauth&amp;gt;.{8})\s(?&amp;lt;connect&amp;gt;.{8})\s(?&amp;lt;instance&amp;gt;\S+)\s(?&amp;lt;end_user&amp;gt;.{16})\s(?&amp;lt;ws_name&amp;gt;.{29})\s(?&amp;lt;transact&amp;gt;.{50})\s\n0(?&amp;lt;origauth&amp;gt;.{8})\s(?&amp;lt;corrname&amp;gt;.{8})\s(?&amp;lt;conntype&amp;gt;.{12})\s"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;On this event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;0=======================================================================================================
 PRIMAUTH CONNECT  INSTANCE       END_USER      WS_NAME                       TRANSACT                                               
 ORIGAUTH CORRNAME CONNTYPE       RECORD TIME   DESTNO     IFC DESCRIPTION    DATA                                                   
 PLANNAME CORRNMBR                TCB CPU TIME             ID                                                                        
 -------- -------- ------------ -------------------------- --- -------------- --------------------------
0A1B2C3   SERVER   X'123456789012' A12345           ABCD123                       SQLA.exe                                           
0Z9Y8X7   N/A      REMOTE     M 15:46:05        1234567890 140 Audit Auth Failures                                                   
0DISTSERV 'BLANK' 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Gives me the following fields and their values (the quotes are mine obviously):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;primauth = "A1B2C3  "
connect = "SERVER  "
instance = "X'123456789012'"
end_user = "A12345          "
ws_name = "ABCD123                      "
transact = "SQLA.exe                                          "
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You get the idea, and you probably see where I'm going with this. &lt;/P&gt;

&lt;P&gt;How can I maintain the fixed field widths for extractions, but disregard trailing spaces in the values (something that you might do with "chomp" in perl). I would rather not have to append a wildcard every time I do a search for a specific field value just because I'm unsure how many spaces there are.&lt;/P&gt;

&lt;P&gt;I very much suspect regex is the solution to my problems here but I've been scratching my head about this for a while.&lt;/P&gt;

&lt;P&gt;Hoping someone can help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 12:41:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96697#M25014</guid>
      <dc:creator>rturk</dc:creator>
      <dc:date>2012-07-12T12:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: Fixed-width field extraction but removing trailing spaces</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96698#M25015</link>
      <description>&lt;P&gt;Why not just use a [^\s]+ to capture everything up until a space character? you can then use a \s+ to move ahead to the start of the next character set.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 13:05:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96698#M25015</guid>
      <dc:creator>Drainy</dc:creator>
      <dc:date>2012-07-12T13:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Fixed-width field extraction but removing trailing spaces</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96699#M25016</link>
      <description>&lt;P&gt;Ahhh... so once again I answer my own question.&lt;/P&gt;

&lt;P&gt;Turns out that specifying the regular expression in your search query will capture spaces in the extracted values, but putting that same regex in your props.conf or transforms.conf will "chomp" the values for you while keeping your fixed-width field definitions.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;props.conf:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[db2_system_parameters]
KV_MODE                 = none
SHOULD_LINEMERGE        = true
BREAK_ONLY_BEFORE       = ^0==
TIME_FORMAT             = %H:%M:%S
MAX_TIMESTAMP_LOOKAHEAD = 800
REPORT-header_fields    = db2_header_fields
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;transforms.conf:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[db2_header_fields]
REGEX = (?m)^0(?&amp;lt;primauth&amp;gt;.{8})\s(?&amp;lt;connect&amp;gt;.{8}) ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps someone else, as it wasn't behaviour I was aware of &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 13:12:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96699#M25016</guid>
      <dc:creator>rturk</dc:creator>
      <dc:date>2012-07-12T13:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Fixed-width field extraction but removing trailing spaces</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96700#M25017</link>
      <description>&lt;P&gt;That was how I approached it initially, but unfortunately not all fields are mandatory so the fixed-width definitions have to be kept for data integrity. Thanks for the suggestion though &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jul 2012 13:14:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96700#M25017</guid>
      <dc:creator>rturk</dc:creator>
      <dc:date>2012-07-12T13:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: Fixed-width field extraction but removing trailing spaces</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96701#M25018</link>
      <description>&lt;P&gt;beware that that solution works until you have AT LEAST one blank between two fields. It you have adjacent fields, with no space in between, then Splunk has problems in handling the two fields as two different strings. &lt;/P&gt;

&lt;P&gt;I had that problem in a case where the log had fixed lenght fields but with adjacent fields(no separators). &lt;BR /&gt;
For instance, envent il something like&lt;/P&gt;

&lt;P&gt;xxxxxyyyyyyyyy....... where field1 are the first 5 chars, then field2 and so on.&lt;/P&gt;

&lt;P&gt;In that case, fields extractions works, but if you try a search line "field1=xxxxx", that Splunk returns no result. To have some result you should write "field1=xxxxx*".&lt;BR /&gt;
This is because Splunk indexes just one string made of "xxxxxyyyyyyy...." And if you have to search for field2, it's event worst: you must write "field2=&lt;EM&gt;yyyyyyyyy&lt;/EM&gt;". As you can imagine, performance implications are terrible!&lt;/P&gt;

&lt;P&gt;The solution I tried (and it worked perfectly) was to use a transform during the parsing phase and write the _raw adding a separator (. or | or a blank) between fields. Then Splunk indexes correctly the fields.&lt;/P&gt;

&lt;P&gt;Marco&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:13:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96701#M25018</guid>
      <dc:creator>marcoscala</dc:creator>
      <dc:date>2020-09-28T18:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Fixed-width field extraction but removing trailing spaces</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96702#M25019</link>
      <description>&lt;P&gt;@Marcoscala&lt;BR /&gt;
U wrote&lt;BR /&gt;
"The solution I tried (and it worked perfectly) was to use a transform during the parsing phase and write the _raw adding a separator (. or | or a blank) between fields. Then Splunk indexes correctly the fields."&lt;/P&gt;

&lt;P&gt;Can you please guide me how to do this? ..I am new in splunk.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 04:52:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Fixed-width-field-extraction-but-removing-trailing-spaces/m-p/96702#M25019</guid>
      <dc:creator>Saurabhsood</dc:creator>
      <dc:date>2017-05-09T04:52:39Z</dc:date>
    </item>
  </channel>
</rss>

