Splunk Search

Help with Rex or RegEx: How do I extract all lines after a string?

arrowecssupport
Communicator

So my email using the iMail Mailbox comes in with headers like this.
I need everything after the "____________________ Message Body ____________________"

How can I look for this?

blah blah blah
MIME-Version = "1.0"
mailbox = "Inbox"
size = 23156
____________________  Message Body  ____________________

Scanning server: xxxx
Time: Tue Jun 14 11:01:46 2016
Sender: xxxx
Recipient(s): xxx
Subject: xxx
File(s):xxxx
Other: Attachment: xxxx
GENERATED_ON=Tue Jun 14 11:00:33 CEST 2016
VERSION=xxx
SYSTEM_xxx
SERIAL_NUMxxxx
HOSTNAME\xx
SEQUENCE\xx
PARTNER_SYSTEM_xxx
PARTNER_SERIAL_NUM=xxxx
PARTNER_HOSTNAME\xxx
0 Karma
1 Solution

javiergn
Super Champion

Let me know if this is what you are looking for:

| stats count | fields - count
| eval _raw = "blah blah blah
MIME-Version = \"1.0\"
mailbox = \"Inbox\"
size = 23156
Message Body

Scanning server: xxxx
Time: Tue Jun 14 11:01:46 2016
Sender: xxxx
Recipient(s): xxx
Subject: xxx
File(s):xxxx
Other: Attachment: xxxx
GENERATED_ON=Tue Jun 14 11:00:33 CEST 2016
VERSION=xxx
SYSTEM_xxx
SERIAL_NUMxxxx
HOSTNAME\xx
SEQUENCE\xx
PARTNER_SYSTEM_xxx
PARTNER_SERIAL_NUM=xxxx
PARTNER_HOSTNAME\xxx
"
| rex field=_raw "(?msi)Message Body\s+(?<body>.*)"

Output:

body
-------
 Scanning server: xxxx
 Time: Tue Jun 14 11:01:46 2016
 Sender: xxxx
 Recipient(s): xxx
 Subject: xxx
 File(s):xxxx
 Other: Attachment: xxxx
 GENERATED_ON=Tue Jun 14 11:00:33 CEST 2016
 VERSION=xxx
 SYSTEM_xxx
 SERIAL_NUMxxxx
 HOSTNAME\xx
 SEQUENCE\xx
 PARTNER_SYSTEM_xxx
 PARTNER_SERIAL_NUM=xxxx
 PARTNER_HOSTNAME\xxx

View solution in original post

javiergn
Super Champion

Let me know if this is what you are looking for:

| stats count | fields - count
| eval _raw = "blah blah blah
MIME-Version = \"1.0\"
mailbox = \"Inbox\"
size = 23156
Message Body

Scanning server: xxxx
Time: Tue Jun 14 11:01:46 2016
Sender: xxxx
Recipient(s): xxx
Subject: xxx
File(s):xxxx
Other: Attachment: xxxx
GENERATED_ON=Tue Jun 14 11:00:33 CEST 2016
VERSION=xxx
SYSTEM_xxx
SERIAL_NUMxxxx
HOSTNAME\xx
SEQUENCE\xx
PARTNER_SYSTEM_xxx
PARTNER_SERIAL_NUM=xxxx
PARTNER_HOSTNAME\xxx
"
| rex field=_raw "(?msi)Message Body\s+(?<body>.*)"

Output:

body
-------
 Scanning server: xxxx
 Time: Tue Jun 14 11:01:46 2016
 Sender: xxxx
 Recipient(s): xxx
 Subject: xxx
 File(s):xxxx
 Other: Attachment: xxxx
 GENERATED_ON=Tue Jun 14 11:00:33 CEST 2016
 VERSION=xxx
 SYSTEM_xxx
 SERIAL_NUMxxxx
 HOSTNAME\xx
 SEQUENCE\xx
 PARTNER_SYSTEM_xxx
 PARTNER_SERIAL_NUM=xxxx
 PARTNER_HOSTNAME\xxx

arrowecssupport
Communicator

Not really, I'm using this to try and extract the email body as i need to see the email headers, but need the body in its own field.

So it would return
Scanning server: xxxx
Time: Tue Jun 14 11:01:46 2016
Sender: xxxx
Recipient(s): xxx
Subject: xxx

File(s):xxxx
Other: Attachment: xxxx
GENERATED_ON=Tue Jun 14 11:00:33 CEST 2016
VERSION=xxx
SYSTEM_xxx
SERIAL_NUMxxxx
HOSTNAME\xx
SEQUENCE\xx
PARTNER_SYSTEM_xxx
PARTNER_SERIAL_NUM=xxxx
PARTNER_HOSTNAME\xxx

0 Karma

javiergn
Super Champion

Sorry I'm confused. Isn't that what my code above is doing?
The regex will create a new field named body and the content is:

 Scanning server: xxxx
 Time: Tue Jun 14 11:01:46 2016
 Sender: xxxx
 Recipient(s): xxx
 Subject: xxx
 File(s):xxxx
 Other: Attachment: xxxx
 GENERATED_ON=Tue Jun 14 11:00:33 CEST 2016
 VERSION=xxx
 SYSTEM_xxx
 SERIAL_NUMxxxx
 HOSTNAME\xx
 SEQUENCE\xx
 PARTNER_SYSTEM_xxx
 PARTNER_SERIAL_NUM=xxxx
 PARTNER_HOSTNAME\xxx
0 Karma

arrowecssupport
Communicator

Yep I had it all wrong. Thanks for your help.

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!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...