Splunk Search

Using rex to extract text from tenable sc output

geoffmx
Explorer

I am attempting to extract the share names from the "pluginText" field below.

pluginText:  <plugin_output>
Here are the SMB shares available on the remote host when logged in as SomeAccount:

  - share1$
  - Share-2$
  - share 3
  - share number 4
  - share - number - 5
  - and_so_on
</plugin_output>    

and require the out put to show like this...

share1$
Share-2$
share 3
share number 4
share - number - 5
and_so_on

I had some luck with this... | rex ":* - (?<pluginText>[^<]*)</plugin_output>" | makemv delim=" - " pluginText
... with the exception of share names that contained a " - ". For example, " share - number - 5" gets split into three separate names because of the delimiter.

I've also tried this... | rex "^[^\-\n]*\-\s+(?<pluginText>[^<]*)" | makemv delim="\n - " pluginText

But it's not consistent. Sometimes, I get the share names as intended, and sometimes it just shows all the text including whats not required.
I'm not very strong with regular expressions, so I'm requesting help to get it right on splunk.

1 Solution

spayneort
Contributor
<search> | rex field=pluginText max_match=100 "\\n\s+-\s(?<share>[^\\n]*)"

View solution in original post

spayneort
Contributor
<search> | rex field=pluginText max_match=100 "\\n\s+-\s(?<share>[^\\n]*)"

geoffmx
Explorer

Thank you! This worked perfectly.

0 Karma

wenthold
Communicator

Try with max_match set to a high value.

| rex max_match=500 "(?:\s*-\s*(?<share_name>.*))" | mvexpand share_name

If you have a field name that contains just the plugin output text with the share list (I'm not familiar with Tenable SC logs) use "field={your field name}" with rex, by default it runs the pattern against the entire _raw message.

lakshman239
Influencer

May not be the best one, but would this help?

\-\s+(?<myshares>........?.?.?.?.?.?.?.?.?.?.?)

https://regex101.com/r/CbiPte/2

0 Karma

geoffmx
Explorer

Thanks Laxman!

It works on the sample set provided, but doesn't when tested with actual logs.

I've managed to get it working with this...

    | rex ":* - (?<pluginText>[^<]*)</plugin_output>" 
    | makemv delim="\n  - " pluginText 
0 Karma

klischatb
Path Finder

Hello,
i tried this regex to get only the "-" out of your text.
Maybe this will help:

\s\s(?(-))\s

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...