Splunk Search

Regex on search output?

jcmaynard
Explorer

Search: index=XXX source=/xxx/xxx/xxxx.log | regex 'something'

How would I do this properly showing just the regexed output?

Thanks...

0 Karma
1 Solution

alacercogitatus
SplunkTrust
SplunkTrust

So there are two ways.

  1. index=xx source=/xx.log | rex field=your_field "(?<your_new_field>REGEX)"| table your_new_field

This shows only the value of the captured regex.

  1. index=xx source=/xx.log | regex _raw="REGEX"

This keeps only the events that match REGEX.

http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Regex
http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex

View solution in original post

0 Karma

jcmaynard2
New Member

The second one gives me the lines with what I'm looking for, when I choose 'View Source', it's giving me the full line and not the extracted data from each line. Can I do that?

0 Karma

rtadams89
Contributor

You can either use the first method and then filter out events where "your_new_field" is null (because the regex didn't match anything). Or you could run the second command given to filter out the relevant events, and then pipe that to the first command to actually do the extraction.

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

So there are two ways.

  1. index=xx source=/xx.log | rex field=your_field "(?<your_new_field>REGEX)"| table your_new_field

This shows only the value of the captured regex.

  1. index=xx source=/xx.log | regex _raw="REGEX"

This keeps only the events that match REGEX.

http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Regex
http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Rex

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...