Splunk Search

How to extract the file name from a file path using rex in a search?

twh1
Communicator

I am getting the file path in my search result. When I am displaying it in dashboard with chart, I need to only extract the file name, not the complete path.

Current output:
/app/wlprd11g/instances/csweb1020/logs/csweb1020_access.log
/app/wlprd11g/instances/csweb1021/logs/csweb1021_access.log
/app/wlprd11g/instances/csweb1022/logs/csweb1022_access.log
/app/wlprd11g/instances/csweb1023/logs/csweb1023_access.log

Desired output:
csweb1020_access.log
csweb1021_access.log
csweb1022_access.log
csweb1023_access.log

0 Karma
1 Solution

twh1
Communicator

I used substr function and got the expected result.

... | eval source=substr(source,40)

View solution in original post

0 Karma

twh1
Communicator

I used substr function and got the expected result.

... | eval source=substr(source,40)

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this.

... | rex "(?:\/?.+\/)*(.+?)$" | ...
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...