Dashboards & Visualizations

Why am I getting this error when attempting extraction of field?

badrinath
Path Finder

Hi all, 

I am working with logs in splunk and here I need to to capture the word before date and time field and the word after it.

ERROR 2022-06-09 xyz-abc

So, using regular expression i wanted to extract the word "error" and "xyz-abc" 

but it is not necessarily the starting of log this phrase can be anywhere  in the log like

log1:

ERROR 2022-06-09 xay-abc  connecting to network.

log2:

java.net.spring ERROR 2022-06-09 connecting to network.

so, please help me with a solution so that I can extract the field which contains error and the other field which contains abc-xyz.

thanks in advance

Labels (2)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @badrinath,

if you're sure that the strings to capture before the date is only one word and that in your log there's only one date, in that format, you could try something like this:

| rex "(?<first_word>\w+)\s+\d\d\d\d-\d\d-\d\d\s+(?<second_word>.*)"

that you can test https://regex101.com/r/MWWag6/1

Ciao.

Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @badrinath,

if you're sure that the strings to capture before the date is only one word and that in your log there's only one date, in that format, you could try something like this:

| rex "(?<first_word>\w+)\s+\d\d\d\d-\d\d-\d\d\s+(?<second_word>.*)"

that you can test https://regex101.com/r/MWWag6/1

Ciao.

Giuseppe

badrinath
Path Finder

thanks, this works well for the first field but comin to second field it capturing the whole log till end but I need only xyz-abc or till the first space

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @badrinath,

if you want only the first word after the date, you can use this:

 

| rex "(?<first_word>\w+)\s+\d\d\d\d-\d\d-\d\d\s+(?<second_word>\w*)"

 

Ciao.

Giuseppe

P.S.: Karma Points are appreciated 😉

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...