Getting Data In

Extracting the last words from my Logfile

pradiptam
Explorer

My logfile has lines like this:

MY_TEST;0;12/12/2014 23:30:14:9000;1;MK69KSS97;TRKCHOP;;4480;EXPORT THE TALISMAN;9;0;0;;Q:\TRKCHOP\POMS\KSKAGNE\IN\STAKK.TXT

i want to extract the the last word that is "STAKK.TXT"

can anybody help me in this?

Tags (1)
0 Karma

mayurr98
Super Champion

Considering the performance of the regex command I think you should try below run anywhere search as you do not need to go via entire event just to get the last string rather you can directly starts from the last.

| makeresults 
| eval _raw="MY_TEST;0;12/12/2014 23:30:14:9000;1;MK69KSS97;TRKCHOP;;4480;EXPORT THE TALISMAN;9;0;0;;Q:\TRKCHOP\POMS\KSKAGNE\IN\STAKK.TXT" 
| rex field=_raw "(?<field>[^\\\\]+$)"

In your environment, you should write

<your base search> | rex field=_raw "(?<field>[^\\\\]+$)"

let me know if this helps!

0 Karma

pradiptam
Explorer

Thanks Mayur

Tried this | rex field=_raw "(?[^\\]+$)" but its not working

Any other suggestions.

Regards,

Pradipta

0 Karma

mayurr98
Super Champion

As from the run anywhere search it is working for the given event. Can you provide some sample events for which it is not working ?

0 Karma

lloydknight
Builder

Hello @pradiptam

Assuming your sample event looks like this.

MY_TEST;0;12/12/2014 23:32:14:9000;1;MK69KSS97;TRKCHOP;;4480;EXPORT THE TALISMAN;9;0;0;;Q:\TRKCHOP\POMS\KSKAGNE\IN\STAKK.TXT

MY_TEST;0;12/12/2014 23:31:14:9000;1;MK69KSS97;TRKCHOP;;4480;EXPORT THE TALISMAN;9;0;0;;Q:\TRKCHOP\POMS\KSKAGNE\IN\STAKK.TXT

MY_TEST;0;12/12/2014 23:30:14:9000;1;MK69KSS97;TRKCHOP;;4480;EXPORT THE TALISMAN;9;0;0;;Q:\TRKCHOP\POMS\KSKAGNE\IN\STAKK.TXT

try this search:

your base search | rex field=_raw ".*\\w+\\w+\\w+\\w+(?<your_field_name>\w+\.\w+)"

Hope it helps!

0 Karma

harsmarvania57
SplunkTrust
SplunkTrust

Hi @pradiptam,

Please try <yourbasesearch> | rex ".*;*\\\(?<extracted_field>\S+)"

I am running below run anywhere search which is generating new field called extracted_field with value STAKK.TXT (First 2 lines in below query are generating sample data only.

| makeresults
| eval _raw="MY_TEST;0;12/12/2014 23:30:14:9000;1;MK69KSS97;TRKCHOP;;4480;EXPORT THE TALISMAN;9;0;0;;Q:\TRKCHOP\POMS\KSKAGNE\IN\STAKK.TXT"
| rex ".*;*\\\(?<extracted_field>\S+)"

I hope this helps.

Thanks,
Harshil

0 Karma

pradiptam
Explorer

Thanks Harshil

Its works for the line only, how do i include my full logfile to get the desired results

Regards,
Pradipta

0 Karma

harsmarvania57
SplunkTrust
SplunkTrust

Hi Pradipta,

Can you please provide your full log sample events ?

0 Karma

miyamaet
Explorer

Try this.

index=your_search |rex "^.*\\\(?P<filename>.*)$"
0 Karma
Get Updates on the Splunk Community!

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...