# CSV Filter Column

**URL:** <https://discuss.elastic.co/t/csv-filter-column/122752>\
**Category:** Logstash\
**Created:** [March 6, 2018, 5:11pm UTC](https://discuss.elastic.co/t/csv-filter-column/122752 "2018-03-06T17:11:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfseth](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@pfseth](https://discuss.elastic.co/u/pfseth)\
**Post date:** [March 6, 2018, 5:11pm UTC](https://discuss.elastic.co/t/csv-filter-column/122752/1 "2018-03-06T17:11:56Z")

</div>

Hi,  
Is it possible to expand column from a variable ?

EnvironmentFile=-/etc/logstash/env  
SCALL='"timestamp","id","app","username"'

Filter  
csv {  
separator =\> "|"  
columns =\> ["${SCALL}"]  
}

---

<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 6, 2018, 5:45pm UTC](https://discuss.elastic.co/t/csv-filter-column/122752/2 "2018-03-06T17:45:32Z")

</div>

> [@pfseth](#):
>
> columns =\> ["${SCALL}"]

Well, it will do the substituion of $SCALL, but columns is still an array containing a single string, so it just sets the name of column 1 to '"timestamp","id","app","username"'.

---

<div class="post-metadata">

**Author:** ![pfseth](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@pfseth](https://discuss.elastic.co/u/pfseth)\
**Post date:** [March 6, 2018, 6:12pm UTC](https://discuss.elastic.co/t/csv-filter-column/122752/3 "2018-03-06T18:12:16Z")

</div>

Is there any way to split the strings ... this is what i am looking for

Instead of this approach

```
filter {
   if "a" in [message] {
           csv {
                     separator => "|"
                     columns => ["a","b","c","d", .......,"z"]
                 }
  } else if "1" in [message]
           csv {
                     separator => "|"
                     columns => ["1","2","3","4", .........,"99"]
                  }
   }
}

```

can i substitute the columns using a variable

```
EnvironmentFile=-/etc/logstash/env
ALPHA='"a","b","c",...........,"z"'
NUM='"1","2","3",..........,"99"'

    filter {
       if "a" in [message] {
               csv {
                         separator => "|"
                         columns => ["${APLHA}"]
                     }
      } else if "1" in [message]
               csv {
                         separator => "|"
                         columns => ["${NUM}"]
                      }
       }
    }

```

Well trying to avoid the repetitive column entries, since i have around 20 if conditions ...

---

<div class="post-metadata">

**Author:** ![tag\_v](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tag_v/32/47466_2.png) [@tag\_v](https://discuss.elastic.co/u/tag_v)\
**Post date:** [March 7, 2018, 7:04pm UTC](https://discuss.elastic.co/t/csv-filter-column/122752/4 "2018-03-07T19:04:29Z")

</div>

you can define environment variables in logstash and use them in filter part. Check this for reference:

[https://www.elastic.co/guide/en/logstash/current/environment-variables.html](https://www.elastic.co/guide/en/logstash/current/environment-variables.html)

---

<div class="post-metadata">

**Author:** ![pfseth](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@pfseth](https://discuss.elastic.co/u/pfseth)\
**Post date:** [March 7, 2018, 7:30pm UTC](https://discuss.elastic.co/t/csv-filter-column/122752/5 "2018-03-07T19:30:53Z")

</div>

Tried, won't work.

```
CSV filter ["${ALPHA}"] takes it as the first column of an array 

    ---- Partial OUTPUT ---

    {
            _index" : "test",
            "_type" : "doc",
            "_id" : "1GLnAWIBad5e0Ecyh3B7",
            "_score" : 1.0,
            "_source" : {
    "a\","b\","c\","d\","e\": "2018-03-05 21:29:31 0500"
              "column2" : "a",
              "column3" : "b",
              "column4" : "c",
              "column5" : "d",
              "column6" : "e",
              "message" : "2018-03-05 21:29:31 -0500|a|b|c|d|e",
              "@timestamp" => 2018-03-07T18:06:11.049Z,
                "@version" => "1"
    }
```

---

<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 4, 2018, 7:31pm UTC](https://discuss.elastic.co/t/csv-filter-column/122752/6 "2018-04-04T19:31:04Z")

</div>

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