Splunk Search

Add line numbers to multiline event using rex in sed mode

alon7786
New Member

Hi,

Is there a way to use fields in rex expression?
I would like to do something like this:

| eval num=1 | accum num | rex mode=sed "s/(?m)^(.)$/*num. \1/g"

meaning adding to multiline event line numbers without breaking the lines.

I tried the How to number each line in a multiline event? but all the suggestions breaking the multiline event to event per line.

I must save the event multiline to perform more actions on the result.

Tags (2)
0 Karma

somesoni2
Revered Legend

You can try like this (run anywhere sample)

| gentimes start=-1 | eval _raw="Line1 
Line2
Line3" | table _raw | rex mode=sed "s/([\r\n])/#$#\1/g" | makemv _raw delim="#$#" | eval sno=mvrange(1,mvcount(_raw)+1) | eval _raw=mvzip(sno,_raw,". ")
0 Karma

alon7786
New Member

Is it impossible? or my questions make no sense?

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...