Splunk Search

How do I extract data from logfile while doing search?

pradiptam
Explorer

I have the following type of logfile

TEST_BEG;0;30/12/2015 10:45:16:1000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;1;0;0;;Q:\MYSHOP\PETS\QPXN.TXT

TEST_LOG;0;30/12/2015 10:45:26:3000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;1;1;;;Start of error rows summary
TEST_LOG;0;30/12/2015 10:45:26:3000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;3;1;;;Error row found for PTENT/00020 at line #1(26)
TEST_LOG;0;30/12/2015 10:45:29:1000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;3;1;;;Error row found for PTLST/00020 at line #1635(8)
TEST_LOG;0;30/12/2015 10:45:33:4000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;3;1;;;Error row found for PTLNT/00020 at line #3

02(3)

In the logfile file, we catch all the data loading activities. Now I want to extract the file name " QPXN.TXT" for which I am getting the error, along with the last numbers in each TEST_LOG at the end of each line like here 26, 8, 3.

How do I go about it, do I need to use regular expressions like regex?

Tags (2)
0 Karma

pradiptam
Explorer

Hi All,

Thanks to all for your help, i am extracting a particular field using regular expression and also prepared a lookup file with this particular value and the fields which i require from the logfile and running my queries to get the desired results.

Regards,

Pradipta

0 Karma

mayurr98
Super Champion

hey if you want all the values in one field then try this

| makeresults | eval raw="TEST_BEG;0;30/12/2015 10:45:16:1000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;1;0;0;;Q:\MYSHOP\PETS\QPXN.TXT,TEST_LOG;0;30/12/2015 10:45:26:3000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;1;1;;;Start of error rows summary,TEST_LOG;0;30/12/2015 10:45:26:3000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;3;1;;;Error row found for PTENT/00020 at line #1(26),TEST_LOG;0;30/12/2015 10:45:29:1000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;3;1;;;Error row found for PTLST/00020 at line #1635(8),TEST_LOG;0;30/12/2015 10:45:33:4000;1;DSLR5590;MYSHOP;;1139;IMPORT OF THE UPDATED MODIFICATIONS;3;1;;;Error row found for PTLNT/00020 at line #302(3)" | makemv raw delim="," | mvexpand raw | rex field=raw ".*(\\\\|(\/\d+\sat\sline\s#\d+\())(?<filename>((\w+\.\w+)|(\d+)))?"

in your environment, you should write

 <base_search> | rex field=_raw ".*(\\\\|(\/\d+\sat\sline\s#\d+\())(?<filename>((\w+\.\w+)|(\d+)))?"

if you want to extract in different fields then try
for filename

<base_search> | rex field=_raw".*\\\\(?<filename>.*)?"

for position

<base_search> | rex field=_raw ".*at\sline.*\((?<position>\d{1})\)?"

let me know if this helps!

0 Karma

Elsurion
Communicator

For the Number you can use this Regex, assuming that the message itself can alter

|rex field=_raw "TEST_LOG.+\((?<position_number>\d+)\)"

For the Logfile you can use this regex

| rex field=_raw "(\S+\\){0,}(?<error_file>\S+)$"

Can you check if the last Regex is working for you? It should not take in account in how many subfolders the file is stored.

0 Karma

mayurr98
Super Champion

all of these events are different or it is in one event only?

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!

[Puzzles] Solve, Learn, Repeat: Classic British Rock Bands

This puzzle series (first published here) is based on extracting information from statements about well-known ...

New to the Community? Join Us for an Exclusive Post .conf26 Welcome Session (Plus a ...

Keep the .conf26 Energy Going: Welcome to the Splunk Community! Whether we scanned your badge at the Community ...

Accelerate Splunk App Development with AI

  Learn how to automate the repetitive parts of your build cycle.   Register to Attend   Join our Tech Talk ...