# Drop line rather than the whole message

**URL:** <https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133>\
**Category:** Logstash\
**Created:** [January 15, 2020, 12:30pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133 "2020-01-15T12:30:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![whoatemyjam](https://avatars.discourse-cdn.com/v4/letter/w/5f9b8f/32.png) [@whoatemyjam](https://discuss.elastic.co/u/whoatemyjam)\
**Post date:** [January 15, 2020, 12:30pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133/1 "2020-01-15T12:30:48Z")

</div>

hi  
I am trying to drop lines which match a regex

```
filter {
if [message] =~ "\e\[8mha.*\e\[0m" { drop{} }
}

```

this above one removes the whole message , how do i drop only the line that contains the matching regex

Thanks

---

<div class="post-metadata">

**Author:** ![grumo35](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grumo35/32/59451_2.png) [@grumo35](https://discuss.elastic.co/u/grumo35)\
**Post date:** [January 15, 2020, 12:57pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133/2 "2020-01-15T12:57:01Z")

</div>

Hi,

Actually i dont think logstash is able to process or understand the concept of lines within a log. It's more likely to process a simple text string.

What do you mean by the line ? can you provide log samples or an example of what your trying to do ?

Thanks.

---

<div class="post-metadata">

**Author:** ![whoatemyjam](https://avatars.discourse-cdn.com/v4/letter/w/5f9b8f/32.png) [@whoatemyjam](https://discuss.elastic.co/u/whoatemyjam)\
**Post date:** [January 15, 2020, 1:04pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133/3 "2020-01-15T13:04:45Z")

</div>

Thanks Grumo

this log is as

> Started by user ^[[8mha:////4Ag0Ig80jDtqRg/RNPPpMGJ+n2VlZliPm5hsa5zI/TRRAAAAmB+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAyOEgYe/dLi1CL94pTEnMQcAONGjhrBAAAA^[[0mshantanu  
> Running in Durability level: MAX\_SURVIVABILITY  
> ^[[8mha:////4MU1hwwmrQi5WMhiBzYpeSIAvmxMsBgiRIwcP4r0nhFEAAAAoh+LCAAAAAAAAP9tjTEOwjAQBM8BClpKHuFItIiK1krDC0x8GCfWnbEdkooX8TX+gCESFVvtrLSa5wtWKcKBo5UdUu8otU4GP9jS5Mixv3geZcdn2TIl9igbHBs2eJyx4YwwR1SwULBGaj0nRzbDRnX6rmuvydanHMu2V1A5c4MHCFXMWcf8hSnC9jqYxPTz/BXAFEIGsfuclm8zQVqFvQAAAA==^[[0m[Pipeline] Start of Pipeline  
> ^[[8mha:////4PvyZR0Eufn8pVijx2W+VC4vO4lzSwW+jYu+Gz5Af9ncAAAApR+LCAAAAAAAAP9tjTEOwjAUQ3+KOrAycohUghExsUZZOEFIQkgb/d8mKe3EibgadyBQiQlLlmxL1nu+oE4RjhQdby12HpP2vA+jK4lPFLtroIm3dOGaMFGwXNpJkrGnpUrKFhaxClYC1hZ1oOTRZdiIVt1VExS65pxj2Q4CKm8GeAAThZxVzN8yR9jeRpMIf5y/AJj7DGxXvP/86jduZBmjwAAAAA==^[[0m[Pipeline] node  
> Running on ^[[8mha:////4HFz2q8kFnRDP54rOdrme553Tm2cBbSad6RlI0bybWm1AAAAnh+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAz2EgZh/eT83ILSktQifY3cxGIgrakPAHib2iPIAAAA^[[0mJenkins in C:\Program Files (x86)\Jenkins\workspace\hello-world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aobrGA93MeeAAAAoh+LCAAAAAAAAP9tjbEOgjAURS8YB1dHP6KEOBon14bFL6hQa6F5D9uHMPlF/pr/IJHEyTvdc5bzemOdIo4cnWotdZ5S7VUfBjc/NXLsroFH1fJF1UyJg1WVHStu7GnBisViWZZjpbGxVAdOnpxgq1vzMEUw5IqzxNkdNHLf3PFEpueymChfmCJ2t6FJTL/O3wCmvhfkZSnI9h+Wl0FxvQAAAA==^[[0m[Pipeline] // node  
> ^[[8mha:////4KY4PpR0M0VKtDOsb5ExOp9v8AJf3pk0dpEoFv+XT3uKAAAAoh+LCAAAAAAAAP9tjTESgjAQRT84FraWHiKMtI6VbYbGE0SIMZDZxWQRKk/k1byDjMxY+av/XvNeb6xTxJGjU62lzlOqverD4OanRo7dNfCoWr6omilxsKqyY8WNPS1YsVgsy3KsNDaW6sDJkxNsdWsepgiGXHGWOLuDRu6bO57I9FwWE+ULU8TuNjSJ6df5G8DU94J8Xwqy8gPQ3eZBvQAAAA==^[[0m[Pipeline] End of Pipeline  
> Finished: SUCCESS

and we want to remove the below

> ^[[8mha:////4Ag0Ig80jDtqRg/RNPPpMGJ+n2VlZliPm5hsa5zI/TRRAAAAmB+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAyOEgYe/dLi1CL94pTEnMQcAONGjhrBAAAA^[[0m

from the logs which has regex of "\e[8mha.\*\e[0m"

will filebeat be able to do it if not logstash ?

---

<div class="post-metadata">

**Author:** ![grumo35](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grumo35/32/59451_2.png) [@grumo35](https://discuss.elastic.co/u/grumo35)\
**Post date:** [January 15, 2020, 1:16pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133/4 "2020-01-15T13:16:22Z")

</div>

Oh, i see there is a lot of trash data in your log.

I would try to find a way to clear the log message before it goes into logstash.

You're issue here are [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences)

Have you tried [this](https://gist.github.com/pauloconnor/4707710)

---

<div class="post-metadata">

**Author:** ![whoatemyjam](https://avatars.discourse-cdn.com/v4/letter/w/5f9b8f/32.png) [@whoatemyjam](https://discuss.elastic.co/u/whoatemyjam)\
**Post date:** [January 15, 2020, 1:50pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133/5 "2020-01-15T13:50:58Z")

</div>

Many Many Thanks Grumo

I used this filter (had to change the pattern a bit)

```
filter {
  mutate {
    gsub => ["message", "\e\[8mha.*\e\[0m", ""]
  }
}

```

and i was able to get the right format

> Started by user shantanu  
> Running in Durability level: MAX\_SURVIVABILITY  
> [Pipeline] Start of Pipeline  
> [Pipeline] node  
> Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\hello-world-pipeline  
> [Pipeline] {  
> [Pipeline] stage  
> [Pipeline] { (Hello)  
> [Pipeline] echo  
> Hello World  
> [Pipeline] }  
> [Pipeline] // stage  
> [Pipeline] }  
> [Pipeline] // node  
> [Pipeline] End of Pipeline  
> Finished: SUCCESS

---

<div class="post-metadata">

**Author:** ![whoatemyjam](https://avatars.discourse-cdn.com/v4/letter/w/5f9b8f/32.png) [@whoatemyjam](https://discuss.elastic.co/u/whoatemyjam)\
**Post date:** [January 15, 2020, 1:51pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133/6 "2020-01-15T13:51:55Z")

</div>

I will try to work out why the original regex from the link to remove the ansi color codes didnot work and get back if i can figure that out  
Thanks

---

<div class="post-metadata">

**Author:** ![grumo35](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grumo35/32/59451_2.png) [@grumo35](https://discuss.elastic.co/u/grumo35)\
**Post date:** [January 15, 2020, 1:55pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133/7 "2020-01-15T13:55:14Z")

</div>

Perfect !

---

<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:** [February 12, 2020, 1:55pm UTC](https://discuss.elastic.co/t/drop-line-rather-than-the-whole-message/215133/8 "2020-02-12T13:55:15Z")

</div>

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