# Timestamp out of UNIXpath

**URL:** <https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374>\
**Category:** Logstash\
**Created:** [January 8, 2019, 1:53pm UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374 "2019-01-08T13:53:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![humalog](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@humalog](https://discuss.elastic.co/u/humalog)\
**Post date:** [January 8, 2019, 1:53pm UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374/1 "2019-01-08T13:53:40Z")

</div>

Hello,  
i try to get a new timestamp which i want to read from a unixpath. I tested with the Grok Debugger. I got smth. what worked, but I think there are better solutions for this.

My sample data:

```
/home/user/file.1.2018.12.22-08.20.log

```

My Grok Pattern:

`%{UNIXPATH:path}%{YEAR:year}.%{MONTHNUM:month}.%{MONTHDAY:day}-%{HOUR:hour}.%{MINUTE:minute}.%{GREEDYDATA:data}`

gives the following json:

{  
"month": "12",  
"data": "log",  
"year": "18",  
"path": "/home/user/file.1.20",  
"day": "22",  
"hour": "08",  
"minute": "20"  
}

Is there a way which is more elegant? How is it possible to get the year with 4 digits?

Best regards

---

<div class="post-metadata">

**Author:** ![A\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_b/32/17104_2.png) [@A\_B](https://discuss.elastic.co/u/A_B)\
**Post date:** [January 8, 2019, 2:05pm UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374/2 "2019-01-08T14:05:43Z")

</div>

This gave me a 4 digit year

> %{UNIXPATH:path}%{NUMBER}.%{YEAR:year}.%{MONTHNUM:month}.%{MONTHDAY:day}-%{HOUR:hour}.%{MINUTE:minute}.%{GREEDYDATA:data}

```
{
  "path": "/home/user/file",
  "month": "12",
  "hour": "08",
  "data": "log",
  "year": "2018",
  "day": "22",
  "minute": "20"
}

```

---

<div class="post-metadata">

**Author:** ![humalog](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@humalog](https://discuss.elastic.co/u/humalog)\
**Post date:** [January 8, 2019, 2:10pm UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374/3 "2019-01-08T14:10:30Z")

</div>

weird, i got error when trying this. after reloading 5 times it works...thank you

---

<div class="post-metadata">

**Author:** ![humalog](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@humalog](https://discuss.elastic.co/u/humalog)\
**Post date:** [January 8, 2019, 4:41pm UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374/4 "2019-01-08T16:41:41Z")

</div>

I created the 4 digit year with this:

> %{UNIXPATH:path}[1.]%{YEAR:year}.%{MONTHNUM:month}.%{MONTHDAY:day}-%{HOUR:hour}.%{MINUTE:minute}.%{GREEDYDATA:data}

Is it possible to create a new @timestamp with my new fields?

Best regards

---

<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:** [January 8, 2019, 4:52pm UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374/5 "2019-01-08T16:52:49Z")

</div>

Don't use [UNIXPATH](https://github.com/logstash-plugins/logstash-patterns-core/issues/159). You can replace it with (?:[^.]+)

To set @timestamp use

```
mutate { add_field => { "ts" => "%{year}/%{month}/%{day} %{hour}:%{minute}" } }
date { match => ["ts", "yyyy/MM/dd HH:mm"] }
```

---

<div class="post-metadata">

**Author:** ![humalog](https://avatars.discourse-cdn.com/v4/letter/h/cc9497/32.png) [@humalog](https://discuss.elastic.co/u/humalog)\
**Post date:** [January 9, 2019, 9:29am UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374/7 "2019-01-09T09:29:30Z")

</div>

This works perfectly, thank you very much.  
When I start my new config (at the moment the one with the old(wrong) timestamp runs), I can't see the changed timestamp. I refreshed my index pattern and the new field is there but I can't see it in the kibana details. When I create a new index the new timestamp works perfectly. Is there a way get the new timestamp works on my "old" index?

---

<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:** [January 9, 2019, 1:28pm UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374/8 "2019-01-09T13:28:59Z")

</div>

I think you would have to re-index.

---

<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:** [February 6, 2019, 1:29pm UTC](https://discuss.elastic.co/t/timestamp-out-of-unixpath/163374/9 "2019-02-06T13:29:03Z")

</div>

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