# Logstash ruby plugin to get the value from file and append

**URL:** <https://discuss.elastic.co/t/logstash-ruby-plugin-to-get-the-value-from-file-and-append/29895>\
**Category:** Logstash\
**Created:** [September 24, 2015, 6:21am UTC](https://discuss.elastic.co/t/logstash-ruby-plugin-to-get-the-value-from-file-and-append/29895 "2015-09-24T06:21:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navneet\_Mathpal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/navneet_mathpal/32/3677_2.png) [@Navneet\_Mathpal](https://discuss.elastic.co/u/Navneet_Mathpal)\
**Post date:** [September 24, 2015, 6:21am UTC](https://discuss.elastic.co/t/logstash-ruby-plugin-to-get-the-value-from-file-and-append/29895/1 "2015-09-24T06:21:35Z")

</div>

Hi,  
I was trying to get the first line from the file and try to append the line into my logs,I am able to get the value from file but not able to append the value ..  
I am doing like

> if[classname] == "java.io.NotSerializableException"   
> {  
> ruby  
> {  
> code =\> "  
> f=File.open('D:/json/samplefile2.txt', &:readline)  
> puts(f) #here I am getting value 1236545  
> "  
> add\_field =\> ["id", "%{f}"] # but here %{f}  
> }  
> }  
> }

Any idea how to resolve it ?

---

<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:** [September 24, 2015, 6:32am UTC](https://discuss.elastic.co/t/logstash-ruby-plugin-to-get-the-value-from-file-and-append/29895/2 "2015-09-24T06:32:02Z")

</div>

```
ruby {
  code => "
    event['id'] = File.open('D:/json/samplefile2.txt', &:readline)
  "
}

```

(Add `.to_i` if you want the `id` field to be an integer field.)

---

<div class="post-metadata">

**Author:** ![Navneet\_Mathpal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/navneet_mathpal/32/3677_2.png) [@Navneet\_Mathpal](https://discuss.elastic.co/u/Navneet_Mathpal)\
**Post date:** [September 24, 2015, 6:39am UTC](https://discuss.elastic.co/t/logstash-ruby-plugin-to-get-the-value-from-file-and-append/29895/3 "2015-09-24T06:39:02Z")

</div>

Thank you @magnusbaeck  
Its working now

---

<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:28am UTC](https://discuss.elastic.co/t/logstash-ruby-plugin-to-get-the-value-from-file-and-append/29895/4 "2017-07-06T05:28:10Z")

</div>


