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!

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...

Index This | When is October more than just the tenth month?

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

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...