Splunk Search

How to extract 3 characters after a given string in Splunk?

avneet26
Engager

I want to extract the two characters 78 from the barvalue  and have it in a separate column in my table:-

 deltavalue = 890(11%) sigmavalue=334(56%) barvalue=445(78%)

 

 

Labels (1)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

Your title says 3 characters, yet the opening sentence says 2 characters.  Which is it?  Also, are you trying to extract all 2-character strings before the percent sign (%) or only the last one?  Specifics are very important when you ask data questions.

Assuming that you only want the last percentage, you can do

| rex field=barvalue "\(?<barpercent>\d+)%\)"

View solution in original post

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Your title says 3 characters, yet the opening sentence says 2 characters.  Which is it?  Also, are you trying to extract all 2-character strings before the percent sign (%) or only the last one?  Specifics are very important when you ask data questions.

Assuming that you only want the last percentage, you can do

| rex field=barvalue "\(?<barpercent>\d+)%\)"
0 Karma

avneet26
Engager

Ah my bad. sorry not three characters. only two numbers i want which is 78 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

In that case, the code provided above should suffice. (You should have a field named barvalue.  Correct?)

0 Karma

avneet26
Engager

barvalue is the search string in my _raw field. 

 

 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

@avneet26 wrote:

barvalue is the search string in my _raw field. 


Are you the admin? If not, you should ask them to make sure obvious key-value pairs are extracted; in fact, unless there is any special settings, Splunk extracts "a=b" in _raw as value "b" assigned to field "a". by default.  With that, my first code should give you a new field barpercent.

But if your admin is uncooperative, you can do something like

| rex "barvalue=\d+\((?<barpercent>\d+)%\)"

Hope this helps. 

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...