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!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...