Splunk Search

How do you take a value out of a field and make a new field with it?

aatha89
Explorer

How do i take out the port number (portnr) from the args field and make it to a field called "port" by a search? Can the answer here be to use eval and rex ?

Tags (1)
0 Karma
1 Solution

Vijeta
Influencer

Yes , you can use this rex command to get port- rex field=Args "_(?<port>\d{4})_"

View solution in original post

Vijeta
Influencer

Yes , you can use this rex command to get port- rex field=Args "_(?<port>\d{4})_"

aatha89
Explorer

Thanks :). Do you think i will need to use eval here? or will it just be fine to use rex ?

0 Karma

Vijeta
Influencer

rex will be fine, no need for eval if you just want to get port number in port field.

0 Karma

aatha89
Explorer

My logline her is:
_time command Args
24.05.1998 17:54 splunkA A_4040_restart

4040 is the portnr. I just want to take out portnr and put it a new field called port

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

try this

YOUR_SEARCH  | rex field=args "_(?<port>.*)_"

Sample:

| makeresults | eval args="A_4040_restart" | rex field=args "_(?<port>.*)_"
0 Karma

aatha89
Explorer

Thank you very much!

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

try
YOUR_SEARCH | rename portnr as port

0 Karma

aatha89
Explorer

Thanks for your reply! But my full question was:

My logline her is:
_time command Args // fields
24.05.1998 17:54 splunkA A_4040_restart //Values

4040 is the portnr. I just want to take out portnr and put it a new field called port

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...