# Grok Pattern for text file

**URL:** <https://discuss.elastic.co/t/grok-pattern-for-text-file/105567>\
**Category:** Logstash\
**Created:** [October 27, 2017, 12:34pm UTC](https://discuss.elastic.co/t/grok-pattern-for-text-file/105567 "2017-10-27T12:34:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranjith](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@ranjith](https://discuss.elastic.co/u/ranjith)\
**Post date:** [October 27, 2017, 12:34pm UTC](https://discuss.elastic.co/t/grok-pattern-for-text-file/105567/1 "2017-10-27T12:34:09Z")

</div>

Hi all,

I'm trying to parse an text file and am not able to grok the PKey in these text.  
Please find the sample text file below.

ac92ec61-5a5c-df11-beff-001ec95274b6,8b2135d0-ba04-4473-8398-3e0e1045c7c4

I am trying in the following way

filter  
{  
grok {  
match =\> ["message","%{DATA:ModelID},%{GREEDYDATA}"]  
match =\> ["GREEDYDATA","{DATA:Pkey}\</PKey\>"]  
}  
}

Please guide me whether I am going in correct way.

Thanks in advance

---

<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:** [October 27, 2017, 12:58pm UTC](https://discuss.elastic.co/t/grok-pattern-for-text-file/105567/2 "2017-10-27T12:58:36Z")

</div>

Wouldn't it be easier to just use a csv filter here? If not I recommend `(?<fieldname>[^,]+)` which matches a sequence of characters up to the first comma.

> match =\> ["GREEDYDATA","{DATA:Pkey}"]

I don't know what you're trying to do here.

---

<div class="post-metadata">

**Author:** ![ranjith](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@ranjith](https://discuss.elastic.co/u/ranjith)\
**Post date:** [October 27, 2017, 1:11pm UTC](https://discuss.elastic.co/t/grok-pattern-for-text-file/105567/3 "2017-10-27T13:11:48Z")

</div>

Thanks magnus

---

<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:** [November 24, 2017, 1:12pm UTC](https://discuss.elastic.co/t/grok-pattern-for-text-file/105567/4 "2017-11-24T13:12:27Z")

</div>

Closed on November 24, 2017, 1:12pm UTC

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