# Pattern to extract specific integer and string

**URL:** <https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332>\
**Category:** Logstash\
**Created:** [August 3, 2022, 5:12pm UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332 "2022-08-03T17:12:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aniket\_Pant](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Aniket\_Pant](https://discuss.elastic.co/u/Aniket_Pant)\
**Post date:** [August 3, 2022, 5:12pm UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332/1 "2022-08-03T17:12:18Z")

</div>

Input:

```auto
CEES:1.0|NGINX|NGINX|1.17.6|400|devTime=03/Aug

```

Output

```auto
response_code: 400
message: devTime=03/Aug

```

Pattern i have applied

```auto
^LEEF.*\|%{INT:response_code}%{GREEDYDATA:log_message

```

Output i got

```auto
response_code: 400
message: |devTime=03/Aug

Unable to solve this anyone please help me
```

---

<div class="post-metadata">

**Author:** ![79g](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/79g/32/109191_2.png) [@79g](https://discuss.elastic.co/u/79g)\
**Post date:** [August 3, 2022, 5:29pm UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332/2 "2022-08-03T17:29:48Z")

</div>

Which are the fields you want to save?

Actually the Input you put there does not match the pattern.

Try something like this:

`%{WORD:word1}:%{NUMBER:n1}\|%{WORD:word2}\|%{WORD:word3}\|%{GREEDYDATA:n2}\|%{NUMBER:response_code}\|%{GREEDYDATA:string}`

 ![pattern](https://us1.discourse-cdn.com/elastic/original/3X/b/5/b50626665fdabbb2827ca8ba19de32c91dd31842.png)

Hope it helps 🙂

---

<div class="post-metadata">

**Author:** ![Aniket\_Pant](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Aniket\_Pant](https://discuss.elastic.co/u/Aniket_Pant)\
**Post date:** [August 3, 2022, 5:36pm UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332/3 "2022-08-03T17:36:27Z")

</div>

Hi @79g unfortunately i have not used kibana dev tool i test this on online grok parsing tool. I want only expected output just want 2 field response\_code and message field after 400 value but i am getting | in front of the message field value

---

<div class="post-metadata">

**Author:** ![79g](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/79g/32/109191_2.png) [@79g](https://discuss.elastic.co/u/79g)\
**Post date:** [August 4, 2022, 7:14am UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332/4 "2022-08-04T07:14:30Z")

</div>

Have you tried to escape the `|` char?

Try the pattern of my previous publication:

```auto
%{WORD:word1}:%{NUMBER:n1}\|%{WORD:word2}\|%{WORD:word3}\|%{GREEDYDATA:n2}\|%{NUMBER:response_code}\|%{GREEDYDATA:string}

```

If you only need two fields, just discard the rest of them

---

<div class="post-metadata">

**Author:** ![Aniket\_Pant](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Aniket\_Pant](https://discuss.elastic.co/u/Aniket_Pant)\
**Post date:** [August 4, 2022, 9:47am UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332/5 "2022-08-04T09:47:52Z")

</div>

Thank you @79g i followed your code and learn it  
My new grok pattern is

```auto
^CEES.*\|%{INT:response_code}\|%{GREEDYDATA:log_message

```

I got my desired outpur using this , but out of curiosity what does `\|` signify ? I mean i got my output just hit and trial

---

<div class="post-metadata">

**Author:** ![79g](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/79g/32/109191_2.png) [@79g](https://discuss.elastic.co/u/79g)\
**Post date:** [August 4, 2022, 10:46am UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332/6 "2022-08-04T10:46:46Z")

</div>

> [@Aniket\_Pant](#):
>
> Thank you @79g i followed your code and learn it

Happy to help 🙂 Just mark my reply as solution for making easier for others to find.

> [@Aniket\_Pant](#):
>
> but out of curiosity what does `\|` signify ?

You can not put the character `|` inside JSON without escaping. Some special characters could be interpreted and cause failures. To avoid this is necessary to add a `\` before. You can search about `json escaping`

---

<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:** [August 4, 2022, 3:57pm UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332/7 "2022-08-04T15:57:59Z")

</div>

> [@Aniket\_Pant](#):
>
> what does `\|` signify ?

By default, | is used for alternation, so that you might match either AM or PM in a timestamp using `(AM|PM)`. If you have a literal | in the message then you need to escape it with a backslash for the regexp to match it.

---

<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:** [September 1, 2022, 3:58pm UTC](https://discuss.elastic.co/t/pattern-to-extract-specific-integer-and-string/311332/8 "2022-09-01T15:58:09Z")

</div>

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