# Remove extra spaces between log messages using mutate & gsub

**URL:** <https://discuss.elastic.co/t/remove-extra-spaces-between-log-messages-using-mutate-gsub/33031>\
**Category:** Logstash\
**Created:** [October 27, 2015, 1:31am UTC](https://discuss.elastic.co/t/remove-extra-spaces-between-log-messages-using-mutate-gsub/33031 "2015-10-27T01:31:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![richinkansal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richinkansal/32/6033_2.png) [@richinkansal](https://discuss.elastic.co/u/richinkansal)\
**Post date:** [October 27, 2015, 1:31am UTC](https://discuss.elastic.co/t/remove-extra-spaces-between-log-messages-using-mutate-gsub/33031/1 "2015-10-27T01:31:27Z")

</div>

Log file Example:

INFO | jvm 1 | 2015/10/19 16:43:35 | logs logs logs text text text  
INFO | jvm 1 | 2015/10/19 16:43:35 | logs logs logs text text text query to execute(in millis) : 28  
INFO | jvm 1 | 2015/10/19 16:43:35 | Time taken by logs logs logs text text textexecute(in millis) : 336  
INFO | jvm 1 | 2015/10/19 16:43:36 | Time taken by 'logs logs logs text text text' query to execute(in millis) : 1122

Logstash Config Used:  
input {  
stdin {  
}  
}

filter{  
mutate {  
gsub =\> ["message","|"," "]  
}  
grok{  
patterns\_dir =\> "C:\Docs\elk\logstash-1.5.4\patterns"  
match =\> ["message", "%{WRAPPERLOG}"]  
}  
date {  
match =\> ["timestamp", "dd/MMM/yyyy:HH:mm:ss Z"]  
}  
}

output{  
stdout{  
codec =\> rubydebug  
}  
}

Grok Patterns Being Developed:  
WRAPPERLOG %{LOGLEVEL:level} %{JVMNAME:jvmname} %{WRAPPER\_DATESTAMP:timestamp} %{GREEDYDATA:logmessage}

JVMNAME %{WORD:jvm} %{INT:number}

WRAPPER\_DATESTAMP 20%{YEAR}/%{MONTHNUM}/%{MONTHDAY} %{HOUR}:?%{MINUTE}(?::?%{SECOND})

I am getting below grokparsefailure message when I tried multiple times, this is my first time using ELK any help is highly appreciated !!

In my config I have gsub for pipe but I am not able to find any gsub for multiple spaces between the log messages, I think that is my problem

![](https://us1.discourse-cdn.com/elastic/original/2X/e/e1e7704135dcda5c524ed1ff5a67742cf6ce62e7.png)

---

<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, 2015, 7:10am UTC](https://discuss.elastic.co/t/remove-extra-spaces-between-log-messages-using-mutate-gsub/33031/2 "2015-10-27T07:10:58Z")

</div>

Why use gsub in the first place? Why not include `\|` in the grok pattern? Use `+` to denote "at least one occurrence of the preceding token" to handle the variable number of spaces.

```
WRAPPERLOG %{LOGLEVEL:level} +\| +%{JVMNAME:jvmname} +\| +%{WRAPPER_DATESTAMP:timestamp} +\| +%{GREEDYDATA:logmessage}
```

---

<div class="post-metadata">

**Author:** ![richinkansal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richinkansal/32/6033_2.png) [@richinkansal](https://discuss.elastic.co/u/richinkansal)\
**Post date:** [October 27, 2015, 5:45pm UTC](https://discuss.elastic.co/t/remove-extra-spaces-between-log-messages-using-mutate-gsub/33031/3 "2015-10-27T17:45:22Z")

</div>

Thanks a lot Magnus ! That was great help, I made the changes suggested by you and removed gsub and boom ! it worked !!

---

<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:** [July 6, 2017, 5:25am UTC](https://discuss.elastic.co/t/remove-extra-spaces-between-log-messages-using-mutate-gsub/33031/4 "2017-07-06T05:25:11Z")

</div>


