Splunk Search

Need to change the value of field using sed

Vignesh-107
Path Finder

I want to replace the values of alertnateId and displayName to "****", I tried with below sed command but its not changing the the whole value.

index=sample
| rex mode=sed "s/(\"alternateId\"\:\s+\")(\w+)/\1****\"/g"
| rex mode=sed "s/(\"displayName\"\:\s+\")(\w+\W)/\1****\"/g"

_raw data:
{"logs_id": "4890d36f-5ee3-11eb-b3a5-852911ef9cd4", "securityContext": { "alternateId": "****"@Anonymous.com", "id": "ramxghl092", "displayName": "****"System"},


Expected is to get 

{"logs_id": "4890d36f-5ee3-11eb-b3a5-852911ef9cd4", "securityContext": { "alternateId": "****", "id": "ramxghl092", "displayName": "****"},

Labels (1)
Tags (1)
0 Karma

KailA
Contributor

Hello,

I guess that you don't have the "****" in the raw data so I did this example for you :

| makeresults 
| eval test = "{\"logs_id\": \"4890d36f-5ee3-11eb-b3a5-852911ef9cd4\", \"securityContext\": { \"alternateId\": \"test.test@gmail.com\", \"id\": \"ramxghl092\", \"displayName\": \"testSystem\"},"
| rex field=test mode=sed "s/(\"alternateId\":\s+\")([^\"]+)/\1****/g"
| rex field=test mode=sed "s/(\"displayName\"\:\s+\")([^\"]+)/\1****/g"

It will match everything till the quotation mark 

 

Let me know if it helps you 🙂

to4kawa
Ultra Champion
index=_internal | head 1 | fields _raw
| eval _raw="{\"logs_id\": \"4890d36f-5ee3-11eb-b3a5-852911ef9cd4\", \"securityContext\": { \"alternateId\": \"****@gmail.com\", \"id\": \"ramxghl092\", \"displayName\": \"****System\"},"
| rex mode=sed "s/((alternateId|displayName)\":\s*)\".*?\"/\1\"*****\"/g"
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

🍂 Fall into November with a fresh lineup of Community Office Hours, Tech Talks, and Webinars we’ve ...

Transform your security operations with Splunk Enterprise Security

Hi Splunk Community, Splunk Platform has set a great foundation for your security operations. With the ...

Splunk Admins and App Developers | Earn a $35 gift card!

Splunk, in collaboration with ESG (Enterprise Strategy Group) by TechTarget, is excited to announce a ...