# How can I check if the log file path contains a certain string in the logstash configuration using regex?

**URL:** <https://discuss.elastic.co/t/how-can-i-check-if-the-log-file-path-contains-a-certain-string-in-the-logstash-configuration-using-regex/224042>\
**Category:** Logstash\
**Created:** [March 18, 2020, 7:48am UTC](https://discuss.elastic.co/t/how-can-i-check-if-the-log-file-path-contains-a-certain-string-in-the-logstash-configuration-using-regex/224042 "2020-03-18T07:48:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Youssef\_SBAI](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youssef_sbai/32/64242_2.png) [@Youssef\_SBAI](https://discuss.elastic.co/u/Youssef_SBAI)\
**Post date:** [March 18, 2020, 7:48am UTC](https://discuss.elastic.co/t/how-can-i-check-if-the-log-file-path-contains-a-certain-string-in-the-logstash-configuration-using-regex/224042/1 "2020-03-18T07:48:05Z")

</div>

I use filebeat to send logs to logstash, based on their file names - these logs are sent to specific indexes in elasticsearch. Filebeat works fine, logstash receives log files, but I can't get the regular expression in my logstash configuration to check if the filenames contain a certain work string.

```
input {
beats {
  port => 5044
 }
}
 filter {
 csv {
   separator => ","
    columns => ["Order ID","Status","Remarks"]
}
 }
     output {
   if [source] =~ "/path/to/my/logs/log-file-1*.csv" {
    stdout {}
     }
   else if [source] =~ "/path/to/my/logs/log-file-2*.csv" {
    stdout {}
    }
  else if [source] =~ "/path/to/my/logs/log-file-3*.csv" {
   stdout {}
   }
  else if [source] =~ "/path/to/my/logs/log-file-4*.csv" {
   stdout {}
   }  
   }

```

Am I referencing [source] the right way?

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [March 19, 2020, 12:28pm UTC](https://discuss.elastic.co/t/how-can-i-check-if-the-log-file-path-contains-a-certain-string-in-the-logstash-configuration-using-regex/224042/2 "2020-03-19T12:28:22Z")

</div>

Can you post here a sample of a document output by logstash?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 22, 2020, 4:22pm UTC](https://discuss.elastic.co/t/how-can-i-check-if-the-log-file-path-contains-a-certain-string-in-the-logstash-configuration-using-regex/224042/3 "2020-03-22T16:22:39Z")

</div>

> [@Youssef\_SBAI](#):
>
> if [source] =~ "/path/to/my/logs/log-file-1\*.csv"

Does it work better if you try

```
if [source] =~ /\/path\/to\/my\/logs\/log-file-1.*\.csv/

```

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [March 31, 2020, 10:10am UTC](https://discuss.elastic.co/t/how-can-i-check-if-the-log-file-path-contains-a-certain-string-in-the-logstash-configuration-using-regex/224042/4 "2020-03-31T10:10:37Z")

</div>

How's my previous answer (which actually is a question) supposed to be a solution to your problem? 🤷‍♂️

---

<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:** [April 28, 2020, 10:10am UTC](https://discuss.elastic.co/t/how-can-i-check-if-the-log-file-path-contains-a-certain-string-in-the-logstash-configuration-using-regex/224042/5 "2020-04-28T10:10:38Z")

</div>

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