Splunk Search

How to customize raw data into fields using regex before exporting to CSV?

zoeygirl45
Explorer

We are ingesting syslog logs. While doing a search and exporting to csv, we would like the raw data column to be split into readable fields. Do I need to use regex?

What can I post here so you can see the raw data?

aljohnson_splun
Splunk Employee
Splunk Employee
  • A more permanent solution would be using transforms.conf and props.conf. Docs here.
  • or use the field extractor ? Docs here
  • or maybe you just love that web gui ? You can manage extractions there as well. Here

Example:

Add a new error code field
This example shows how to create a new "error code" field by configuring a field extraction in props.conf. The field can be identified by the occurrence of device_id= followed by a word within brackets and a text string terminating with a colon. The field should be extracted from events related to the testlog source type.

In props.conf, add:

[testlog]
EXTRACT-errors = device_id=\[w+\](?<err_code>[^:]+)

Or get jiggy with that GUI:
alt text

0 Karma

rlough
Path Finder

You can try using the "erex" command that Splunk has. This command basically creates your rex call for you.

Here's how it works:

... YOUR SEARCH ... | erex FIELD_NAME examples="2345,3455,9283"

After your search, use the erex command by replacing FIELD_NAME with a name of your choice and then post real examples of the data that you want to be put in this field (you only need two or three examples). These examples of yours will replace the dummy data that I have above in between quotes. Your examples must be comma separated and surrounded by quotes.

After your search runs, the rex command that it creates for you can be found under the "Jobs" tab.

sk314
Builder

you could post a few lines from your logs itself...

esix_splunk
Splunk Employee
Splunk Employee

If this is syslog, and your timestamps and events are being recognized correctly, you can use the Field Extractor Utility to extract fields as you desire. And then using the fields and outputcsv commands, you can format how you want your CSV to look.

Other options as mentioned are using props and transforms to create your own extractions and fields.

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!

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...