Splunk Search

multiline match for same pattern

tven
Explorer
<Product>
 <ProductName>(\w+)</ProductName>
 <ProductName>(\w+)</ProductName>
 <ProductName>(\w+)</ProductName>
</Product>

How do i capture all the product name when the number of ProductName elements is variable? And not sure how to assign the group capture to a named variable when you have 0 or more ProductNames.

index=xyz sourcetype=abc |rex "(?s)<ProductName>(?P<product_sku>\w+)</ProductName>" captures one occurence.

0 Karma

kristian_kolb
Ultra Champion

Have you looked at MV_ADD=true in order to get more than the last value?

Basically, you need to do the following changes/additions on your search head, or on your indexer if you don't have a dedicated search head;

in props.conf

[your_xml_sourcetype]
REPORT-gimme_codes = prod_code_extraction

in transforms.conf

[prod_code_extraction]
REGEX = <ProductName>([^<]+)<
FORMAT = product_sku::$1
MV_ADD = True

Hope this helps,

Kristian

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...