Splunk Search

How to get a comma separated List

brownt61
Explorer

Hello all,

I am hoping for help creating a comma separated list.  I have tried multiple different things and all have resulted in lists, but never quite what I am needing.  

I have a list of email addresses, that I need to be listed out, comma separated so that I can automate a currently manual process of updating a DLP policy.

The list would appear as follows

input data:

Email
[email protected]

[email protected]

[email protected]

[email protected]

[email protected]

...

...

[email protected]

[email protected]

 

The output list that I need comma separated needs to be displayed as follows

EmailAddress

[email protected],

[email protected],

[email protected],

[email protected],

[email protected],

...

...

[email protected],

[email protected]

 

note that the list is comma separated however the final entry does not get a comma.  This is because Symantec DLP reconizes the comma separator as an expected new entry.  If there is no comma, the final entry is expected as the last entry. 

 

I have tied stats list (this worked) however, it limits the output to 100 (I have around 1500 email addresses).  I know that I could have the limits.conf increased from 100, but I would like to avoid this just do accomplish this one task.

 

I have also tried to string the fields to string the , however it places the comma at the end of the final value in the list.
| eval EmailAddress=Email+","
| table EmailAddress

I have also tried mvjoin which just creates a giant mv field, which would be ok, expect some of the email addresses have a - in them, which then line breaks resulting in the .csv file being sent out break and have emails not formatted correctly.

I have also tried delim with a dc and values, however it also just creates a giant mv list with commas at the end of all values including the end value.

| stats delim="," dc(Email) as EmailAddressCount, values(Email) as EmailAddress
| nomv EmailAddress
| table EmailAddress

Is there a way to create the comma separated list as requested? or is there an easier way to remove the trailing character from the LAST value?

Thank you

0 Karma
1 Solution

mthomas_splunk
Splunk Employee
Splunk Employee

To generate the source data, I used:

 

| makeresults count=1500
| streamstats count
| eval email="email"+count+"@email.com"
| fields - _time, count

 

then to combine it, it used:

 

| mvcombine email delim=","
| nomv email

 

Which results in:

 

[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],emai....

 

Alternatively, you can use the following to leave the email addresses in separate  events:

 

| reverse 
| streamstats count
| eval email=if(count>1,email+",",email)
| fields - count
| reverse

 

which results in:

 

[email protected],
[email protected],
[email protected],
[email protected],
...
[email protected],
[email protected]

 

Hopefully one of those does what you're after?

View solution in original post

mthomas_splunk
Splunk Employee
Splunk Employee

To generate the source data, I used:

 

| makeresults count=1500
| streamstats count
| eval email="email"+count+"@email.com"
| fields - _time, count

 

then to combine it, it used:

 

| mvcombine email delim=","
| nomv email

 

Which results in:

 

[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],emai....

 

Alternatively, you can use the following to leave the email addresses in separate  events:

 

| reverse 
| streamstats count
| eval email=if(count>1,email+",",email)
| fields - count
| reverse

 

which results in:

 

[email protected],
[email protected],
[email protected],
[email protected],
...
[email protected],
[email protected]

 

Hopefully one of those does what you're after?

brownt61
Explorer

| reverse | streamstats count | eval email=if(count>1,email+",",email) | fields - count | reverse

This is exactly what I needed.  Thank you

Tags (1)
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!

Splunk App Dev Quarterly Roundup: AI, Agents, and Innovation!

Another quarter, another wave of innovation. From complex integrations to pushing the limits ...

Federated Search for Dynamic Data Self Storage Is Now Generally Available on Splunk ...

 Splunk is excited to announce the General Availability of Federated Search for Dynamic Data Self Storage ...

Index This | What has many keys but can’t unlock a door?

July 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...