Splunk Enterprise

How to extract different formats of files with common regex?

Ashwini008
Builder

I have below filename where i need to capture only the bold part.But all these files are in the same location.i cannot use single regex that applies to all the below file format.

How do i proceed on capturing the required format?

worldtime.xml.1
ztymp.txt.1
molu.dat.1
jss_pyuroly_7.dat.1
zpiyzygh.rtnugbhti.1
AD.CD.MBOUDN.1
DM.DEVT.IYP.IN.1

zpiyrmlu.rage.600.1.txt.1
in_zpiyrmlu.rage.600.1.txt.1
in_soledt.pou.til.ssn.gpg.1.txt.1

zprunsledSCALLb1.prn.1

Tags (4)
0 Karma

manjunathmeti
SplunkTrust
SplunkTrust

hi @Ashwini008 ,

You can strip file extensions from the file name.

| eval filename=replace(filename, "\.(xml|txt|dat|gpg|prn|1)", "")

 

Sample query:

| makeresults 
| eval _raw="filename
worldtime.xml.1
ztymp.txt.1
molu.dat.1
jss_pyuroly_7.dat.1
zpiyzygh.rtnugbhti.1
AD.CD.MBOUDN.1
DM.DEVT.IYP.IN.1
zpiyrmlu.rage.600.1.txt.1
in_zpiyrmlu.rage.600.1.txt.1
in_soledt.pou.til.ssn.gpg.1.txt.1
zprunsledSCALLb1.prn.1" 
| multikv forceheader=1 
| eval filename=replace(filename, "\.(xml|txt|dat|gpg|prn|1)", "")

 

If this reply helps you, an upvote/like would be appreciated.

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

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 ...