# Extract a string from logstash path

**URL:** <https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126>\
**Category:** Kibana\
**Created:** [December 17, 2017, 6:03pm UTC](https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126 "2017-12-17T18:03:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshishC](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashishc/32/45312_2.png) [@AshishC](https://discuss.elastic.co/u/AshishC)\
**Post date:** [December 17, 2017, 6:03pm UTC](https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126/1 "2017-12-17T18:03:30Z")

</div>

Hi Everyone,

I am using logstash to send raw data ELK. Logstash config input section reads as:  
input {  
file {  
path =\> ["D:/apache-jmeter-3.3/bin/Booking\_Stress\_Test.csv"]  
start\_position =\> "beginning"  
}  
}

Now, in Kibana, this path i.e. "D:/apache-jmeter-3.3/bin/Booking\_Stress\_Test.csv" is shown under the "path.keyword" field.

I can pull the entire path using Data Table Visualization. But I want to extract just the test name instead of entire path.

In this case, I want to extract and show sub-string "Booking\_Stress\_Test" only. Do I need to use JSON Input formatting? Any assistance is highly appreciated!

Many Thanks,  
Ashish

---

<div class="post-metadata">

**Author:** ![Kurt\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kurt_s/32/17755_2.png) [@Kurt\_S](https://discuss.elastic.co/u/Kurt_S)\
**Post date:** [December 18, 2017, 12:26am UTC](https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126/2 "2017-12-18T00:26:49Z")

</div>

In Logstash, you could apply the grok filter on the path field to extract the filename. If I remember correctly there are patterns for files and paths in de default grok patterns.

---

<div class="post-metadata">

**Author:** ![AshishC](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashishc/32/45312_2.png) [@AshishC](https://discuss.elastic.co/u/AshishC)\
**Post date:** [December 18, 2017, 12:52am UTC](https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126/3 "2017-12-18T00:52:12Z")

</div>

Hi Kurt,

Thanks for the quick response! Where in logstash should I use grok? And how it will show on Kibana Dashboard?

---

<div class="post-metadata">

**Author:** ![Kurt\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kurt_s/32/17755_2.png) [@Kurt\_S](https://discuss.elastic.co/u/Kurt_S)\
**Post date:** [December 20, 2017, 2:29pm UTC](https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126/4 "2017-12-20T14:29:34Z")

</div>

In the filter section.

filter {  
grok {  
match =\> { "path" =\> " your pattern here" }  
}  
}

More info on how to do this can be found in the documentation:  
[https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html](https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html)

---

<div class="post-metadata">

**Author:** ![AshishC](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashishc/32/45312_2.png) [@AshishC](https://discuss.elastic.co/u/AshishC)\
**Post date:** [December 20, 2017, 3:03pm UTC](https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126/5 "2017-12-20T15:03:43Z")

</div>

Hi Kurt, Thanks!

earlier I couldn't get your solution but yeah now I understand bit of grok and how it works. Many thanks for your response and solving the issue.

One more thing, I see grok extracts everything that matches the pattern. Would have been great if we can extract the group(s).

path =\> ["D:/apache-jmeter-3.3/bin/PerfTest\_ModuleName\_1\_1219.csv"]

grok {  
match =\> ["path", "(?/(\w\*).)"]  
}

grok output : "/PerfTest\_ModuleName\_1\_1219."  
But I was expecting the string from group, by group I mean text enclosed in ( ). i.e. PerfTest\_ModuleName\_1\_1219.

Something similar to left, right boundaries.

Thanks,  
Ashish

---

<div class="post-metadata">

**Author:** ![Kurt\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kurt_s/32/17755_2.png) [@Kurt\_S](https://discuss.elastic.co/u/Kurt_S)\
**Post date:** [December 21, 2017, 10:46pm UTC](https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126/6 "2017-12-21T22:46:53Z")

</div>

I think this pattern should work to match what you look for in the field "group"

> grok {  
> match =\> ["path", "/%{WORD:group}.csv$"]  
> }

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 18, 2018, 10:46pm UTC](https://discuss.elastic.co/t/extract-a-string-from-logstash-path/112126/7 "2018-01-18T22:46:59Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
