Splunk Search

how to remove a portion of string

leecholim
Engager

Hi all,

my data as below:

11111_aaaa/ppppaaaa

1110_bb/kjm

I want to remove anything after /, like this

11111_aaaa

1110_bb

 

Thanks.

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @leecholim,

let me understand: do you want to remove the part of the event at index time (before indexing) or at search time (when data is displayed)?

In the second case, you have to use a simple regex like this to extract only the part of the field that you want.

E.g.: if the field containing the data to cut is "my_field", try something like this:

| rex field=my_field "^(?<my_new_field>[^\/]*)"

If instead you want to delete the part of the event before indexing, you have to use the SEDCMD command (for more infos see at https://docs.splunk.com/Documentation/Splunk/8.2.1/Data/Anonymizedata) but in this case you cannot use the other information contained in the deleted part of the event.

I cannot give you the regex to do this because I need some sample of the full events.

Ciao.

Giuseppe

View solution in original post

0 Karma

jwalthour
Communicator

Use the rex command and have regex cut it down.

| makeresults

| eval foo=“11111_aaaa/ppppaaaa”

| rex field=foo “^(?P<foo>[^\/]*)”

This uses regex on the foo field to take everything from the beginning of that field until the “/“ and assign back to the field foo.

0 Karma

leecholim
Engager

length before / is different for data...

0 Karma

leecholim
Engager

thanks, will try.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @leecholim,

good for you, see next time.

Remember to accept the answer for the other people of Community and Karma Points are appreciated by all the Contributors.

Ciao and happy splunking.

Giuseppe

0 Karma

jwalthour
Communicator

leecholim -

Please mark an answer as your solution once you’ve tried.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @leecholim,

lenght isn't relevant!

Ciao.

Giuseppe

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @leecholim,

let me understand: do you want to remove the part of the event at index time (before indexing) or at search time (when data is displayed)?

In the second case, you have to use a simple regex like this to extract only the part of the field that you want.

E.g.: if the field containing the data to cut is "my_field", try something like this:

| rex field=my_field "^(?<my_new_field>[^\/]*)"

If instead you want to delete the part of the event before indexing, you have to use the SEDCMD command (for more infos see at https://docs.splunk.com/Documentation/Splunk/8.2.1/Data/Anonymizedata) but in this case you cannot use the other information contained in the deleted part of the event.

I cannot give you the regex to do this because I need some sample of the full events.

Ciao.

Giuseppe

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

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

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...