# How to extract a specific string from a log after a match in grok filter?

**URL:** <https://discuss.elastic.co/t/how-to-extract-a-specific-string-from-a-log-after-a-match-in-grok-filter/173473>\
**Category:** Logstash\
**Created:** [March 22, 2019, 10:06am UTC](https://discuss.elastic.co/t/how-to-extract-a-specific-string-from-a-log-after-a-match-in-grok-filter/173473 "2019-03-22T10:06:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![WarriorHarb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warriorharb/32/43201_2.png) [@WarriorHarb](https://discuss.elastic.co/u/WarriorHarb)\
**Post date:** [March 22, 2019, 10:06am UTC](https://discuss.elastic.co/t/how-to-extract-a-specific-string-from-a-log-after-a-match-in-grok-filter/173473/1 "2019-03-22T10:06:55Z")

</div>

Hello,  
So i have a multi-lined log, each line has a format, after creating a grok filter that detects the keyword "callid" ,i would like to extract the ID right after that keyword and save it to a new field. here is a sample of 3 lines from the log file:

> _Jan 21 14:00:34.499_ OPCM35AVCS207 VCS: [0x00001dfc] ScriptManager 0x11111111 for thread 0x22222222 for tenant \*\*\*\*\*\*\*\* has removed a thread. Total: 1 thread(s).  
> _Jan 21 14:00:34.499_ OPCM35AVCS207 VCS: [0x00001dfc] CSScriptCall::Release DELETE **callid=0x0a0a0a0a0a0a0a0a** Hitsign hi  
> _Jan 21 14:00:34.499_ OPCM35AVCS207 VCS: [0x00001dfc] CCall destroyed at 0x4691aa28

i would like to extract that **0x0a0a0a0a0a0a0a0a** into a new field. (note that all of those IDs have the same length 18 caracters), i have created a GROK filter that detects every line that has the word "callid" and create a new field that containes the word callid or void (in case the wod wasn't detected) .  
any suggestions will be apperciated.

---

<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 22, 2019, 1:01pm UTC](https://discuss.elastic.co/t/how-to-extract-a-specific-string-from-a-log-after-a-match-in-grok-filter/173473/2 "2019-03-22T13:01:42Z")

</div>

How about

```
    grok {
        match => { "message" => 'callid=(?<callid>[0-9a-fx]{18})' }
    }
```

---

<div class="post-metadata">

**Author:** ![WarriorHarb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warriorharb/32/43201_2.png) [@WarriorHarb](https://discuss.elastic.co/u/WarriorHarb)\
**Post date:** [March 22, 2019, 1:09pm UTC](https://discuss.elastic.co/t/how-to-extract-a-specific-string-from-a-log-after-a-match-in-grok-filter/173473/3 "2019-03-22T13:09:24Z")

</div>

hi @Badger, thanks for the quick reply.  
How would i save it to a new field to visualize its content later ?

---

<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 22, 2019, 1:10pm UTC](https://discuss.elastic.co/t/how-to-extract-a-specific-string-from-a-log-after-a-match-in-grok-filter/173473/4 "2019-03-22T13:10:37Z")

</div>

That will save it to a field called "callid".

---

<div class="post-metadata">

**Author:** ![WarriorHarb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warriorharb/32/43201_2.png) [@WarriorHarb](https://discuss.elastic.co/u/WarriorHarb)\
**Post date:** [March 22, 2019, 1:20pm UTC](https://discuss.elastic.co/t/how-to-extract-a-specific-string-from-a-log-after-a-match-in-grok-filter/173473/5 "2019-03-22T13:20:34Z")

</div>

@Badger thanks a lot , you're a life-saver

---

<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, 2019, 1:20pm UTC](https://discuss.elastic.co/t/how-to-extract-a-specific-string-from-a-log-after-a-match-in-grok-filter/173473/6 "2019-04-19T13:20:37Z")

</div>

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