Splunk Search

Extract string within specific tag

kirangurram
Explorer

Hello Experts ,
Need your assistance to extract output from one of the below XML tags.
I have three XML tags with same naming convention and I want only extract specific value 3 from the below tags.
can you help me to provide rex commend (or) any other commend which will only extract value 3 from the below tags.

<Val Ty="CHAR">Feedback</Val>
<Val Ty="CHAR">3</Val>
<Val Ty="CHAR">TRST</Val>

your help is much appreciated.

Tags (1)
0 Karma
1 Solution

vnravikumar
Champion

Hi

Try this

|makeresults  |eval tag="<Val Ty=\"CHAR\">Feedback</Val>
<Val Ty=\"CHAR\">3</Val>
<Val Ty=\"CHAR\">TRST</Val>" |rex field=tag "CHAR\"\>(?P<output>(\d+))\<"

OR

| makeresults 
| eval tag="<Val Ty=\"CHAR\">Feedback</Val>
 <Val Ty=\"CHAR\">3</Val>
 <Val Ty=\"CHAR\">TRST</Val>" 
| rex field=tag max_match=0 "\"CHAR\">(?P<output>.+)<" 
| eval result = mvindex(output,1)

View solution in original post

0 Karma

kirangurram
Explorer

Thanks @vnravikumar , below solution works.
Second solution didnt give me desired results.

|makeresults |eval tag="Feedback
3
TRST" |rex field=tag "CHAR\">(?P(\d+))<"

0 Karma

vnravikumar
Champion

Hi

Try this

|makeresults  |eval tag="<Val Ty=\"CHAR\">Feedback</Val>
<Val Ty=\"CHAR\">3</Val>
<Val Ty=\"CHAR\">TRST</Val>" |rex field=tag "CHAR\"\>(?P<output>(\d+))\<"

OR

| makeresults 
| eval tag="<Val Ty=\"CHAR\">Feedback</Val>
 <Val Ty=\"CHAR\">3</Val>
 <Val Ty=\"CHAR\">TRST</Val>" 
| rex field=tag max_match=0 "\"CHAR\">(?P<output>.+)<" 
| eval result = mvindex(output,1)
0 Karma
Get Updates on the Splunk Community!

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

What are Community Office Hours?Community Office Hours is an interactive 60-minute Zoom series where ...

Updated Data Type Articles, Anniversary Celebrations, and More on Splunk Lantern

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

A Prelude to .conf25: Your Guide to Splunk University

Heading to Boston this September for .conf25? Get a jumpstart by arriving a few days early for Splunk ...