Splunk Search

Extract field names from CSV header

JIthesh_Kumar
Explorer

Hi Team,
my CSV file contains a field like bellow (1st line in CSV) How can i create transformation for field extraction 

"State","Location name","Primary Number"

its retrieving a field state and Location

Expected Fields:
State
Location name
Primary Number

Labels (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

You needs are probably better served by INDEXED_EXTRACTIONS=csv (index time extraction) or KV_MODE=csv (search time) in sourcetype.  Using regex to handle structured data like CSV is very fragile.

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

If your column order is known and does not change, you can define delimiter-based extractions in props.conf for your sourcetype. But then you must explicitly name the fields and their order. Otherwise the only way to handle such file is using indexed extractions (which has its own drawbacks). Remember that indexed extractions happen on the initial forwarder!

isoutamo
SplunkTrust
SplunkTrust

If you can define which line contains headers and which values, then you can do this with any countable columns. It’s enough to known how many columns you could maximum have.

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

this is doable, but probably it needs some way to recognize which line is header line. And position in file is not that. But as @yuanliu said it's much better to use INDEXED_EXTRACTIONS=csv and then define HEADER_FIELD_LINE_NUMBER if it didn't recognize automatically that header line.

You should put props.conf also on your UF to get this work.

Structured Data Header Extraction and configuration

r. Ismo

yuanliu
SplunkTrust
SplunkTrust

You needs are probably better served by INDEXED_EXTRACTIONS=csv (index time extraction) or KV_MODE=csv (search time) in sourcetype.  Using regex to handle structured data like CSV is very fragile.

Get Updates on the Splunk Community!

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...

Getting Started with Splunk Artificial Intelligence, Insights for Nonprofits, and ...

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