Splunk Search

How to divide a value from a string into fields?

Luninho
Explorer

I have value in field:

value: 10,5 CC,00136;CY,00004;JE,00004;QK,00004

Where  CC,CY,JE - type message and there are more of them than in example

00136,00004 - number of message

But I need to get table:

TypeCount
CC136
CY4
JE4

 

How can i do it with SPL language?

Labels (3)
0 Karma

johnhuang
Motivator

Assuming the type is always 2 uppercase alphabet characters:

| rex field=value "\s(?<_raw>([A-Z]{2}\,\d{5}\;)+([A-Z]{2}\,\d{5})?)"
| extract kvdelim="," pairdelim=";" 
| transpose | regex column="[A-Z]{2}"
| rename column AS Type "row 1" AS count 
| eval count=tonumber(count)
| table Type count

 

You can substitute with this regex to extract the pattern from your raw data instead of the field value -- test to see which works better. 

| rex "\s(?<_raw>([A-Z]{2}\,\d{5}\;)+([A-Z]{2}\,\d{5})?)"

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Luninho,

are the types in fixed positions?

if they are in fixed posiztion (e.g. 1st, 3rd 5th position) or identificable e.g. for a newar char (e.g. ; just before), you can create a regex to extract them, otherwise it's very difficoult.

Cold you share some additional samples?

From the one you shared the only rule I can identify is that there's a comma just after, it always has a two upper char.

If this is correct you could creat a regex like this:

| rex "(\s|;)(?<Type>\w\w),"

that you can test at https://regex101.com/r/GuqZpU/1

Ciao.

Giuseppe

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...