# Edit file using logstash

**URL:** <https://discuss.elastic.co/t/edit-file-using-logstash/312157>\
**Category:** Logstash\
**Created:** [August 16, 2022, 9:29am UTC](https://discuss.elastic.co/t/edit-file-using-logstash/312157 "2022-08-16T09:29:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex\_vermex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_vermex/32/101267_2.png) [@alex\_vermex](https://discuss.elastic.co/u/alex_vermex)\
**Post date:** [August 16, 2022, 9:29am UTC](https://discuss.elastic.co/t/edit-file-using-logstash/312157/1 "2022-08-16T09:29:35Z")

</div>

Hi,  
I have already created a topic [here](https://discuss.elastic.co/t/add-to-codec-json/312104) to add `[]` to the beginning and end of the file and I can't find the solution so I want to ask if I can edit the file using logstash now my file like this:

```auto
{"field1": "value1","field2":"value2"}{"field3":"value3"} .... 

```

so i want to add `[` at the beginning of the file and `]` at the end of the file

Any help would be sincerely appreciate!  
Thanks!

---

<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 16, 2022, 6:00pm UTC](https://discuss.elastic.co/t/edit-file-using-logstash/312157/2 "2022-08-16T18:00:02Z")

</div>

You can use a mutate filter to gsub square brackets onto the start and end of the field.

---

<div class="post-metadata">

**Author:** ![alex\_vermex](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_vermex/32/101267_2.png) [@alex\_vermex](https://discuss.elastic.co/u/alex_vermex)\
**Post date:** [August 16, 2022, 6:08pm UTC](https://discuss.elastic.co/t/edit-file-using-logstash/312157/3 "2022-08-16T18:08:55Z")

</div>

yes, i can edit a **field** using gsub but i can't edit the **file** with gsub

---

<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 13, 2022, 6:09pm UTC](https://discuss.elastic.co/t/edit-file-using-logstash/312157/4 "2022-09-13T18:09:54Z")

</div>

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