# How can I read the last 5 records from a file?

**URL:** <https://discourse.nodered.org/t/how-can-i-read-the-last-5-records-from-a-file/33112>\
**Category:** Dashboard\
**Created:** [20 September 2020 13:45 UTC](https://discourse.nodered.org/t/how-can-i-read-the-last-5-records-from-a-file/33112 "2020-09-20T13:45:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![manjha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/manjha/32/29301_2.png) [@manjha](https://discourse.nodered.org/u/manjha)\
**Post date:** [20 September 2020 13:45 UTC](https://discourse.nodered.org/t/how-can-i-read-the-last-5-records-from-a-file/33112/1 "2020-09-20T13:45:55Z")

</div>

I have a flow that reads a txt file. Output is a complete list of records, which I would like to parse.  
I tried several of the available parsers, the csv parser works, but returns each record as a separate output.  
Is there a smarter way to do this?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 September 2020 14:56 UTC](https://discourse.nodered.org/t/how-can-i-read-the-last-5-records-from-a-file/33112/2 "2020-09-20T14:56:43Z")

</div>

You could try using an exec node to run 'tail'.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 September 2020 15:09 UTC](https://discourse.nodered.org/t/how-can-i-read-the-last-5-records-from-a-file/33112/3 "2020-09-20T15:09:08Z")

</div>

In fact there is a Tail node I believe `node-red-node-tail`

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 September 2020 15:36 UTC](https://discourse.nodered.org/t/how-can-i-read-the-last-5-records-from-a-file/33112/4 "2020-09-20T15:36:28Z")

</div>

You can set the csv node to return an array if you wish... or use a join node after it to rejoin each line... depends what you wish to achieve.

---

<div class="post-metadata">

**Author:** ![manjha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/manjha/32/29301_2.png) [@manjha](https://discourse.nodered.org/u/manjha)\
**Post date:** [21 September 2020 21:22 UTC](https://discourse.nodered.org/t/how-can-i-read-the-last-5-records-from-a-file/33112/5 "2020-09-21T21:22:14Z")

</div>

Solved it: parse file output into an array, then take last five entries. Simple!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 October 2020 21:22 UTC](https://discourse.nodered.org/t/how-can-i-read-the-last-5-records-from-a-file/33112/6 "2020-10-05T21:22:18Z")

</div>

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