Splunk Search

How to count specific data separated by pipe character ?

Linnie25
New Member

Hi,

I have below data and would like to get count by country code. Is it possible to get it ?

|21/02/2021 12:36:29.048| |INFO| |1234|guest |CA|1.10.1| [END] - DetailsLookUp

|21/02/2021 12:26:20.534| |INFO| |8669|guest |US|1.10.1| [END] - DetailsLookUp

Thanks in advance.

Labels (1)
Tags (3)
0 Karma

Linnie25
New Member

@AhmadKhattak20 @inventsekar @inventsekar 

Thanks for giving me the ideas how to work this out.

There is no field specify for the country code so I use Field Extractor and now I'm able to get the count 😊

But since I use source as Data Type I'm not able to change the Permission. From what I read it seems like there is issue when using source instead of sourcetype.

0 Karma

inventsekar
SplunkTrust
SplunkTrust

Hi @Linnie25 

If the fields are not extracted, then, you have to use rex to find out the country and then count. 

| makeresults 
| eval log="|test|13e|1234|guest |CA|1.2|test|test" 
| rex field=log "\|(?<country>\w\w)\|\d" 
| stats count by country

rex.png

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma

tscroggins
Influencer

@Linnie25 

As implied, you need to extract the country code value into a field. At search time, you can use the rex command with an appropriate regular expression:

| rex "\\|[^|]*\\|[^|]*\\|[^|]*\\|[^|]*\\|[^|]*\\|[^|]*\\|(?<country_code>[^|]*)"
| stats count by country_code

0 Karma

AhmadKhattak20
Explorer

What are the fields that have been extracted for this data?

Is there any field extracted that has the country code value, if so then you can easily get the count by country code.

As an example,

If the field containing the country code is called "code", you could get the count by country code using the below SPL query, 

index=main | stats count by code

Replace the index value with the actual index in which the data is being stored. 

0 Karma
Get Updates on the Splunk Community!

Advanced Splunk Data Management Strategies

Join us on Wednesday, May 14, 2025, at 11 AM PDT / 2 PM EDT for an exclusive Tech Talk that delves into ...

Uncovering Multi-Account Fraud with Splunk Banking Analytics

Last month, I met with a Senior Fraud Analyst at a nationally recognized bank to discuss their recent success ...

Secure Your Future: A Deep Dive into the Compliance and Security Enhancements for the ...

What has been announced?  In the blog, “Preparing your Splunk Environment for OpensSSL3,”we announced the ...