# Match a string and then assign this string to the output field

**URL:** <https://discuss.elastic.co/t/match-a-string-and-then-assign-this-string-to-the-output-field/169698>\
**Category:** Logstash\
**Created:** [February 24, 2019, 3:29am UTC](https://discuss.elastic.co/t/match-a-string-and-then-assign-this-string-to-the-output-field/169698 "2019-02-24T03:29:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozmhsh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ozmhsh/32/49129_2.png) [@ozmhsh](https://discuss.elastic.co/u/ozmhsh)\
**Post date:** [February 24, 2019, 3:29am UTC](https://discuss.elastic.co/t/match-a-string-and-then-assign-this-string-to-the-output-field/169698/1 "2019-02-24T03:29:33Z")

</div>

I have a requirement to match a string out the log, say 'ABC123' or 'XYZ456'.

Once this is identified, I want to assign this string into the output field. How can I do it? I can obviously use add\_field with the hardcode value, but it will be tedious to do so and end up with many grok statement. Any better way?

---

<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:** [March 24, 2019, 3:29am UTC](https://discuss.elastic.co/t/match-a-string-and-then-assign-this-string-to-the-output-field/169698/2 "2019-03-24T03:29:38Z")

</div>

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