# How to add a timestamp from the previous line to the current line

**URL:** <https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600>\
**Category:** Logstash\
**Created:** [October 25, 2021, 3:32pm UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600 "2021-10-25T15:32:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anoopahamad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anoopahamad/32/96326_2.png) [@anoopahamad](https://discuss.elastic.co/u/anoopahamad)\
**Post date:** [October 25, 2021, 3:32pm UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600/1 "2021-10-25T15:32:25Z")

</div>

In my log file, some of the lines don't have a timestamp. I want to assign the previous line's timestamp to the lines that don't have the timestamp.

I tried "memorize" but that's giving some errors.

Is there a way we can do this?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 25, 2021, 3:43pm UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600/2 "2021-10-25T15:43:57Z")

</div>

Welcome!

Which tool are you using to collect the logs?

---

<div class="post-metadata">

**Author:** ![anoopahamad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anoopahamad/32/96326_2.png) [@anoopahamad](https://discuss.elastic.co/u/anoopahamad)\
**Post date:** [October 25, 2021, 5:18pm UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600/3 "2021-10-25T17:18:16Z")

</div>

I am new to ELK and doing some tests. I am copying the files to a folder manually and from there using logstash passing to the Elasticsearch

This is my logstash config input portion.

```auto
input {
  file {
    path => "C:/../../logwithexceptions22.log"
    start_position => "beginning" 
	
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 26, 2021, 2:55am UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600/4 "2021-10-26T02:55:52Z")

</div>

I moved your question to #elastic-stack:logstash

Have a look at [Aggregate filter plugin | Logstash Reference [7.15] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-filters-aggregate.html) but I'm not sure if this could help.

That's weird that your logs are not coming with a timestamp for every line of log. May be you could fix the logs?

Could you share some sample lines of logs?

---

<div class="post-metadata">

**Author:** ![anoopahamad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anoopahamad/32/96326_2.png) [@anoopahamad](https://discuss.elastic.co/u/anoopahamad)\
**Post date:** [October 26, 2021, 4:39am UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600/5 "2021-10-26T04:39:42Z")

</div>

```auto
10/01/2021 14:24:55.840 JST Thread-4 (22.002.01) INFORMATIVE: SubProcess "/deployment/abcdef/ConfigServer" appears to have been manually started
10/01/2021 14:24:55.847 JST Thread-4 (22.001.18) ACCOUNTING: Process /deployment/abcdef/ConfigServer state is changed to CMDL_MANUAL. Process has started manually or by request.
10/01/2021 14:25:00.836 JST main (20.002.03) CRITICAL: Cannot find configuration for abcdefg during AdminAgentServer.configAdminAgent(). 
com.hp.siu.utils.EntryNotFoundException: /deployment/abcdefg
	at com.hp.siu.utils.ConfigManager.readConfigTree(ConfigManager.java:276)

```

I want to add the stack trace of the logs(last 2 lines) with the previous line's timestamp. Otherwise, it gives the grok parse failure, or even if I handle it properly, it gets the date and time of the processing time for these lines.

---

<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:** [October 26, 2021, 5:27pm UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600/6 "2021-10-26T17:27:46Z")

</div>

You could use a multiline codec on the file input to combine the error and the stacktrace into a single event. Something like

```
codec => multiline {
    pattern => "^\d{2}/\d{2}/\d{4} "
    negate => true
    what => previous
    auto_flush_interval => 5
}
```

---

<div class="post-metadata">

**Author:** ![anoopahamad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anoopahamad/32/96326_2.png) [@anoopahamad](https://discuss.elastic.co/u/anoopahamad)\
**Post date:** [October 27, 2021, 5:18am UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600/7 "2021-10-27T05:18:32Z")

</div>

Thank you Badger.. It's working

---

<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 24, 2021, 5:18am UTC](https://discuss.elastic.co/t/how-to-add-a-timestamp-from-the-previous-line-to-the-current-line/287600/8 "2021-11-24T05:18:40Z")

</div>

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