Getting Data In

Splitting fields with slashes

ajlBXsplunk
New Member

Anyone else having trouble or have guidance to split fields backslashes such as with file paths?

The field value is displayed as:

folder1\folder2\file.txt

And the raw value is:

folder1\\folder2\\file.txt

I have tried this with no luck:

| eval RelativeTargetNameSplit = split(RelativeTargetName, '\')
| eval RelativeTargetNameSplit = split(RelativeTargetName, '\\')
| eval RelativeTargetNameSplit = split(RelativeTargetName, '\\\\')
0 Karma
1 Solution

ddrillic
Ultra Champion

| eval RelativeTargetNameSplit = split("aaaaaXbbbb", "X") just worked for me with double quotes and not single ones around the X.

View solution in original post

0 Karma

ddrillic
Ultra Champion

| eval RelativeTargetNameSplit = split("aaaaaXbbbb", "X") just worked for me with double quotes and not single ones around the X.

0 Karma

ajlBXsplunk
New Member

You're right, When dealing with slashes, use quotes (").

| eval RelativeTargetNameSplit = split(RelativeTargetName, "\\")
0 Karma

ddrillic
Ultra Champion

| eval RelativeTargetNameSplit = split("folder1\folder2\file.txt", "\") worked as well.

0 Karma

ajlBXsplunk
New Member

| eval RelativeTargetNameSplit = split("folder1\folder2\file.txt", "\") does work for me but not with the input is from a field (as opposed to an explicit string)

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Your example data has backslashes, your attempts have forward slashes.

0 Karma

ajlBXsplunk
New Member

Oops, updated to include the right slashed. Thanks for pointing that out.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...