Splunk Search

How to extract data from a multiline field?

ahogbin
Communicator

Hello,

I am trying to extract data from a field ("Files:") that holds multiple lines of data. The lines that I am after are the ones called destination (as per the below example)

Files:
source:/opt/fteStaging/sys/sftpwbcs01_sys/OUT/ACCV01.ALL.20150825.gpg
destination:/TO_EIG/ACCV01.ALL.20150825.gpg
source:/opt/fteStaging/sys/sftpwbcs01_sys/OUT/BATCH.ALL.20150825.gpg
destination:/TO_EIG/BATCH.ALL.20150825.gpg
source:/opt/fteStaging/sys/sftpwbcs01_sys/OUT/BTRN01.ALL.20150825.gpg
destination:/TO_EIG/BTRN01.ALL.20150825.gpg
source:/opt/fteStaging/sys/sftpwbcs01_sys/OUT/BTRN03.ALL.20150825.gpg
destination:/TO_EIG/BTRN03.ALL.20150825.gpg
source:/opt/fteStaging/sys/sftpwbcs01_sys/OUT/BTRNI1.ALL.20150825.gpg
destination:/TO_EIG/BTRNI1.ALL.20150825.gpg
source:/opt/fteStaging/sys/sftpwbcs01_sys/OUT/CASH.ALL.20150825.gpg
destination:/TO_EIG/CASH.ALL.20150825.gpg
source:/opt/fteStaging/sys/sftpwbcs01_sys/OUT/CLAM.ALL.20150825.gpg
destination:/TO_EIG/CLAM.ALL.20150825.gpg

There are approximately 30 entries, each with the same format (source and destination).

I have looked at some of the other questions around this, but none really match my requirements, and with limited knowledge of regex, I am a bit stuck (assuming that is that regex is the way to go).

The field that holds the data that I am after (Files:) is not in itself an extracted field.

The end result of what I am trying to do is to then parse each 'destination' value against a lookup table to determine if all files were ftp'd successfully, or if any were missed (the same type, name and number of files should be transmitted each day).

Any help or pointers will be greatly appreciated.

Many thanks,

Alastair

0 Karma
1 Solution

woodcock
Esteemed Legend

Try this:

... | rex max_match=0 "(?ms)^(?:(?:source:(?<source>.*?))|(?:destination:(?<destination>.*?)))$" | eval type="logs" | append [|inputcsv YourFileWithCSVs | eval type="csv" ] | stats values(*) AS * dc(type) AS numTypes by destination | where numTypes<2

This presumes that the CSV file has a field called destination.

View solution in original post

0 Karma

woodcock
Esteemed Legend

Try this:

... | rex max_match=0 "(?ms)^(?:(?:source:(?<source>.*?))|(?:destination:(?<destination>.*?)))$" | eval type="logs" | append [|inputcsv YourFileWithCSVs | eval type="csv" ] | stats values(*) AS * dc(type) AS numTypes by destination | where numTypes<2

This presumes that the CSV file has a field called destination.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...