Splunk Search

How to create a regex for extracting few characters of a field?

surekhasplunk
Communicator

My VLAN value looks like below:

|inputlookup vrf_usage.csv | search VRF="*" | search VLAN=Vlan819(RVP_CDN) 

Could you please help me getting VLAN value as Vlan819 just before ( symbol. That is just before the bracket starts.

0 Karma

woodcock
Esteemed Legend

Come back and click Accept on the best answer, @surekhasplunk!

0 Karma

woodcock
Esteemed Legend

There are many ways. Here is another one:

... | rex field=VLAN mode=sed "s/\(.*$//"

For example:

| makeresults 
| eval VLAN="vlan(foo)" 
| rex field=VLAN mode=sed "s/\(.*$//"
0 Karma

vnravikumar
Champion

Hi

Try this,

| makeresults 
| eval VLAN ="Vlan819(RVP_CDN)" 
| eval result = mvindex(split(VLAN,"("),0)
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi surekhasplunk,
it could be useful to share a sample of your logs.
Anyway, you could use something like this

| rex "Vlan819<VLAN>\w+)"

to test with a sample.

Bye.
Giuseppe

0 Karma

renjith_nair
Legend

@surekhasplunk ,

Try

|rex field=VLAN "(?<VLAN>.+)\("
---
What goes around comes around. If it helps, hit it with Karma 🙂

ddrillic
Ultra Champion

Looks great -

| makeresults 
| eval VLAN="Vlan819(RVP_CDN)" 
| rex field=VLAN "(?<VLAN>.+)\("
0 Karma
Get Updates on the Splunk Community!

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

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...