Splunk Search

How to keep only the first 5 lines of a multi-line event?

garypark
New Member

In my logs I have a lot of java errors that are about 100 lines long. I would like to filter the event at the universal forwarder and keep only the first 5 lines. I would like single line events to be unaffected.

I have the following settings, but they don't seem to be working for me.

In inputs.conf

[monitor:///app/tmp/test-GP/test*]
sourcetype = test-GP
index = test-gp
disabled = 0
whitelist = .log$

In props.conf

[test-GP]
TRANSFORMS-shortenEvents = keepOnly5Lines

In transforms.conf

[keepOnly5Lines]
REGEX = (?m)^(.*\n){1,5}
FORMAT = $1
DEST_KEY = _raw

0 Karma

somesoni2
Revered Legend

Try this for your transforms.conf (keeping everything else same, your current config just keeps first 5 line in the file and remove all other entries)

[keepOnly5Lines] 
REGEX = (?m)^((.*\n){5})((.*\n)*)
FORMAT = $1
DEST_KEY = _raw
0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...