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!

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...

Secure Your Future: Mastering Upgrade Readiness for Splunk 10

Spotlight: The Splunk Health Assistant Add-On  The Splunk Health Assistant Add-On is your ultimate companion ...

Observability Unlocked: Kubernetes & Cloud Monitoring with Splunk IM

Ready to master Kubernetes and cloud monitoring like the pros? Join Splunk’s Growth Engineering team on ...