Splunk Search

How to replace a specific character?

quangtran
Explorer

Hi,

I have the below output :

1/16/2023 7:51:43 AM 1EE8 PACKET 000001D9C25E6180 UDP Rcv 10.8.64.132 646b Q [0001 D NOERROR] A (6)framer(3)com(0)
UDP question info at 000001D9C25E6180
Socket = 940
Remote addr 10.8.64.132, port 55646
Time Query=9030678, Queued=0, Expire=0
Buf length = 0x0fa0 (4000)
Msg length = 0x001c (28)
Message:
XID 0x646b
Flags 0x0100

The desired output

name=framer.com

IP=10.8.64.132

I using regex: 

sourcetype=DNSlog |rex field=_raw "NOERROR]\W+(?P<name>.*)\sUDP \S.*\s Socket.*\s Remote addr\W+(?P<IP>.*)," | rex mode=sed field=name "s/[\d;()]+//g" |stats count by name IP

 

My below code isn't working, can you please help me?

Labels (1)
0 Karma

yeahnah
Motivator

Hi @quangtran 

The first rex extraction you're using will not match newlines (\n) or carriage returns (\r) so does not work.

Based on your example inputs, you could try something like this


sourcetype=DNSlog
| rex "\].+?\)(?P<subdomain>[^(]+).+?\)(?P<topleveldomain>[^(]+)(?:.+?[\r\n]){3}Remote addr (?P<IP>[^,]+)"
| eval name=subdomain . "." . topleveldomain
| stats count BY name IP


 I web sight like https://regex101.com/ is a good place to test and modify your regular expressions out to get them working.

Hope this helps

quangtran
Explorer

thanks you, I think my regex is correct, but i don't replace a number and specific character with space

quangtran_0-1673841705036.png

 

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...