# Extract logs from a file that start with a line and end with a known line do this for the whole file using logstash

**URL:** <https://discuss.elastic.co/t/extract-logs-from-a-file-that-start-with-a-line-and-end-with-a-known-line-do-this-for-the-whole-file-using-logstash/328216>\
**Category:** Logstash\
**Created:** [March 22, 2023, 7:58am UTC](https://discuss.elastic.co/t/extract-logs-from-a-file-that-start-with-a-line-and-end-with-a-known-line-do-this-for-the-whole-file-using-logstash/328216 "2023-03-22T07:58:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chikugerson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chikugerson/32/118742_2.png) [@chikugerson](https://discuss.elastic.co/u/chikugerson)\
**Post date:** [March 22, 2023, 7:58am UTC](https://discuss.elastic.co/t/extract-logs-from-a-file-that-start-with-a-line-and-end-with-a-known-line-do-this-for-the-whole-file-using-logstash/328216/1 "2023-03-22T07:58:21Z")

</div>

```auto
input {

  file {
		path => "C:/Users/user/Documents/Logstash/mylogs/spa2.log"
		start_position => "beginning"    
  }
}
filter {
  if "SPAHGW:31 32 30 30 :004:: 1200" in [message] {
    grok {
      match => { "message" => "^SPAHGW:31 32 30 30 :004:: 1200 %{GREEDYDATA:start_message}" }
    }
  }
  
  if "SPAHGW:39 39 :032:: 99" in [message] {
    grok {
      match => { "message" => "^SPAHGW:39 39 :032:: 99 %{GREEDYDATA:end_message}" }
    }
  }
}

```

Im trying to ingest logs from this line SPAHGW:31 32 30 30 :004:: 1200  
include all the lines in between upto this line SPAHGW:39 39 :032:: 99 able to get from the start line but getting the logs upto the second line isnt working, and ingesting logs starting with different lines too

---

<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 19, 2023, 7:58am UTC](https://discuss.elastic.co/t/extract-logs-from-a-file-that-start-with-a-line-and-end-with-a-known-line-do-this-for-the-whole-file-using-logstash/328216/2 "2023-04-19T07:58:46Z")

</div>

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