Splunk Search

How to list content between two strings from RAW text?

akapoor47
New Member

Here is the raw text - 

com.companyname.package: stringstart e-38049e11-72b7-4968-b575-ecaa86f54e02 stringend for some.datahere with status FAILED, Yarn appId application_687987, Yarn state FINISHED, and Yarn finalStatus FAILED with root cause: samppleDatahere: com.packagenamehere: Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: sjhdjksdn


Need to list down the uuid which is in between stringstart and stringend 

Labels (2)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

Well, you need to simply find something between your "anchors". Which in simplest form might just be

stringstart\s(?<uuid>.*)\sstringend

If you know that the uuid has some particular form you can be a bit more specific (for example not to capture wrongly formed uuid)

stringstart\s(?<uuid>[0-9a-f]-[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})\sstringend

You can even add more anchoring text in front or at the end if you have more constant parts.

So as you have a regex matching and extracting this part, you can - depending on your use case - either use it as @marnall showed with rex command or use it to define a search-time extraction. For example

EXTRACT-uuid = stringstart\s(?<uuid>[0-9a-f]-[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})\sstringend
0 Karma

marnall
Motivator

I am not sure specifically what you want to do, but if you have that _raw data in an event, and you would like to extract the uuid into a field, then you can make a regex with a named capture group in the rex command to extract it during search time. If you would like this to be permanent then you can copy the regex into a Field Extraction.

<yoursearch>
| rex field=_raw "com.companyname.package: (stringstart\s)?(?<uuid>\S+) (stringend )?for"

I made the assumptions that there are no space characters in the uuid string, and that it is surrounded by "com.companyname.package: and "for"

0 Karma
Get Updates on the Splunk Community!

Splunk Enterprise Security(ES) 7.3 is approaching the end of support. Get ready for ...

Hi friends!    At Splunk, your product success is our top priority. With Enterprise Security (ES), we're here ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...