Splunk Search

How To Eval Filename As A New Field?

vtsguerrero
Contributor

Shoud it be done in the props.conf stanza at the moment of indexing?
I'm gonna have multiple .txt files indexed and later for a dashboard I need to get these filename to compare each other's values.
Is there a way to create a new field using eval for these filenames?

Thanks in advance!
- Vinicius Guerrero

0 Karma
1 Solution

aweitzman
Motivator

The filename should show up in the source field, right? Why not just use it from there?

View solution in original post

aweitzman
Motivator

The filename should show up in the source field, right? Why not just use it from there?

vtsguerrero
Contributor

But will I be able to table it as a result? Is there any example on how to use it?

0 Karma

aweitzman
Motivator

It's a field like any other field you might have. You can include it in a table ( table source field1 field2... ), you can use it to group your results ( stats sum(field1) by source ), you can create another field by applying a regex to it ( rex field=source "regex-goes-here" ). Anything you can do with a text field you can do with source.

0 Karma

vtsguerrero
Contributor

Thanks @awitzman ! it worked!
I thought it wouldn't work for multiple files, but seems ok without a regex.

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!

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 ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...