Splunk Search

Field extraction

sandeepmakkena
Contributor

I have field in my raw events

src = https://www.abcd.com/shop/buy-laptop/dell-200
src= https://www.abcd.com/shop/buy-mobile/LG-i20

I want to extract files product family and products. family like laptop, mobile and Products values like dell-200, LG-i20

Thanks for your time.

0 Karma
1 Solution

MuS
Legend

Hi sandeepmakkena,

Try something like this:

your search here
| rex field=src "buy-(?<family>[^\/]+)\/(?<product>.+)$"
| more SPL here

This will return a field called family and product with values of laptop or mobile respectively dell-200 or LG-i20 based on your provided sample events.

Hope this helps ...

cheers, MuS

View solution in original post

0 Karma

MuS
Legend

Hi sandeepmakkena,

Try something like this:

your search here
| rex field=src "buy-(?<family>[^\/]+)\/(?<product>.+)$"
| more SPL here

This will return a field called family and product with values of laptop or mobile respectively dell-200 or LG-i20 based on your provided sample events.

Hope this helps ...

cheers, MuS

0 Karma

jacobpevans
Motivator

Greetings @sandeepmakkena,

Please try this run-anywhere search. Pick and choose the values you need.

| makeresults
| eval src = "https://www.abcd.com/shop/buy-laptop/dell-200"
| append 
    [ | makeresults 
      | eval src= "https://www.abcd.com/shop/buy-mobile/LG-i20" ]
| rex field=src "(?<category>[^/]+)/[^/]+$"
| rex field=src "buy-(?<category_no_buy>[^/]+)/[^/]+$"
| rex field=src "(?<item>[^/]+)$"
| table src category_no_buy category item

Output:

src                                        category_no_buy   category      item
https://www.abcd.com/shop/buy-laptop/dell-200    laptop      buy-laptop dell-200
https://www.abcd.com/shop/buy-mobile/LG-i20    mobile        buy-mobile LG-i20
Cheers,
Jacob

If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.
0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...