# Grok filter ignore first line always

**URL:** <https://discuss.elastic.co/t/grok-filter-ignore-first-line-always/117359>\
**Category:** Logstash\
**Created:** [January 28, 2018, 12:40pm UTC](https://discuss.elastic.co/t/grok-filter-ignore-first-line-always/117359 "2018-01-28T12:40:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![parthkdas](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@parthkdas](https://discuss.elastic.co/u/parthkdas)\
**Post date:** [January 28, 2018, 12:40pm UTC](https://discuss.elastic.co/t/grok-filter-ignore-first-line-always/117359/1 "2018-01-28T12:40:52Z")

</div>

I am trying to read large csv and txt file from different sources.  
The sources may give us csv or txt file for same data.  
I want to ignore the first the line of each files when they are first time parsed , as they represnt headers.

**sample csv file content:**  
Center,Amount,Date  
xxxx,2222,12-08-2017  
xxxy,6222,12-08-2017  
xxxz,2022,12-08-2017  
xxxa,1222,12-08-2017

**sample txt file content**  
Amount,Date,Center  
2222,12-09-2017,xxxy  
6222,12-09-2017,xxxa  
2022,12-09-2017,xxxz  
1222,12-09-2017,xxxc

**content logstash conf file to read csv files:**

input {  
file {  
path =\> "/Volumes/External/RnD/logstash/inputdata/amount\*.csv"  
type =\> "parse"  
start\_position =\> "beginning"  
sincedb\_path =\> "/Volumes/External/RnD/logstash/sincedb.txt"  
}  
}

filter {  
if [type] == "parse" {  
grok {  
match =\> { "message" =\> "%{WORD:Center},(?[^,]_),(?[^,]_)" }  
}  
}  
}

output {  
if [type] == "parse" {  
if "\_grokparsefailure" in [tags] {  
file {  
path =\> "/Volumes/External/RnD/logstash/outputdata/failed.txt"  
codec =\> line { format =\> "%{message}"}  
}  
}  
csv {  
path =\> "/Volumes/External/RnD/logstash/outputdata/success.txt"  
fields =\> ["Center", "Amount", "Date"]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [January 29, 2018, 8:35am UTC](https://discuss.elastic.co/t/grok-filter-ignore-first-line-always/117359/2 "2018-01-29T08:35:04Z")

</div>

Use a conditional that checks if the `message` field in the current event matches the expected pattern. If it doesn't, run a drop filter that, well, drops the current event.

---

<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:** [February 26, 2018, 8:35am UTC](https://discuss.elastic.co/t/grok-filter-ignore-first-line-always/117359/3 "2018-02-26T08:35:33Z")

</div>

Closed on February 26, 2018, 8:35am UTC

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