# Copy last line of file to another file if the size of the first file is increasing

**URL:** <https://discuss.elastic.co/t/copy-last-line-of-file-to-another-file-if-the-size-of-the-first-file-is-increasing/203601>\
**Category:** Logstash\
**Created:** [October 15, 2019, 9:05am UTC](https://discuss.elastic.co/t/copy-last-line-of-file-to-another-file-if-the-size-of-the-first-file-is-increasing/203601 "2019-10-15T09:05:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_Cincu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrian_cincu/32/55912_2.png) [@Adrian\_Cincu](https://discuss.elastic.co/u/Adrian_Cincu)\
**Post date:** [October 15, 2019, 9:05am UTC](https://discuss.elastic.co/t/copy-last-line-of-file-to-another-file-if-the-size-of-the-first-file-is-increasing/203601/1 "2019-10-15T09:05:11Z")

</div>

Hi, i wrote the output of some logs to a file called interface\_up. I would like to copy the last line of this file to another file compare.txt ( lines in this file will be overwrite each time).

Can you help me please?

output {  
if [message] =~ "changed state to up" {  
file { path =\> "/home/adrian/from\_logstash/interface\_up" write\_behavior =\> "append" }  
} else if [message] =~ "changed state to down" or [message] =~ "changed state to administratively down" {  
file { path =\> "/home/adrian/from\_logstash/interface\_down" }  
} else {  
file { path =\> "/home/adrian/from\_logstash/other\_events" }  
}  
}

---

<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:** [November 12, 2019, 9:05am UTC](https://discuss.elastic.co/t/copy-last-line-of-file-to-another-file-if-the-size-of-the-first-file-is-increasing/203601/2 "2019-11-12T09:05:14Z")

</div>

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