Splunk Search

Adding rex to only part of search

DamianS
Explorer

Hi all,

I have 2 different log file types, 1 of which I currently need to add fields in search time and the other already has them generated. I don't currently have permissions to change this.

In my head the search looks something like:

( log_type="log1" | rex field=_raw "PERL FOO to create FIELD1"  )
OR 
( log_type="log2" )

FIELD1 exists in both log1 and log2 but uses different regex to produce this, in log2 splunk already extracts it. But Splunk doesn't let me put parenthesis around these pipe things.

Any suggestions on how I just get the "rex" to apply to log1 but search on log1 and log2?

Thanks in advance.

Tags (1)
0 Karma

Ayn
Legend

You can't split up the search pipeline like that, but what you could do if field1 isn't extracted at all for log1 is to extract your field using rex anyway. So just:

log_type="log1" OR log_type="log2" | rex "(?<field1>someregex)"

Just make sure the regex only matches the log1 events, so that it doesn't overwrite the correct extraction that's already done in log2.

kristian_kolb
Ultra Champion

please provide some (perhaps sanitized) log lines from both sources, and you'll most likely get help with the regex syntax.

/k

0 Karma

DamianS
Explorer

Actually much quicker to get what I was looking for than I expected using this site to test my regex http://gskinner.com/RegExr/

Thanks again!

0 Karma

DamianS
Explorer

Thanks, I'd tried this but I don't currently have the PERL refex skills to work this out, guess it's time to drastically improve these skills.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...