# How to merge multiple csv into one

**URL:** https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248
**Category:** General
**Created:** [31 August 2020 10:48 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248 "2020-08-31T10:48:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [31 August 2020 10:48 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248/1 "2020-08-31T10:48:38Z")

</div>

I am generating several csv that I want to merge into one so that I can send it by email,  
The idea is that when pressing the timestamp I take the files I want from the path and merge them into 1 sooo, I have looked at how to do it with python and I could do it with the python node but I would like to be able to generate everything with Node Red , any suggestion Please

 ![N1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6ff4da9c4f20c859963d4a44d0a35d72e6a69e9f.png)

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [31 August 2020 11:16 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248/2 "2020-08-31T11:16:38Z")

</div>

There are probably easier methods, but you could try this flow:

```auto
[{"id":"3a79ae2c.9908ea","type":"inject","z":"6bf9fb85.abde3c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":132,"y":504,"wires":[["8fa40c3a.81cc4","4469c52c.6b30a4"]]},{"id":"8fa40c3a.81cc4","type":"file in","z":"6bf9fb85.abde3c","name":"","filename":".node-red/test.csv","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":306,"y":480,"wires":[["c5a4ce2b.a5eed8"]]},{"id":"b18add9e.c07308","type":"debug","z":"6bf9fb85.abde3c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1130,"y":504,"wires":[]},{"id":"c5a4ce2b.a5eed8","type":"csv","z":"6bf9fb85.abde3c","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":506,"y":504,"wires":[["d5d50c16.bcd7e"]]},{"id":"4469c52c.6b30a4","type":"file in","z":"6bf9fb85.abde3c","name":"","filename":".node-red/test.csv","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":306,"y":528,"wires":[["c5a4ce2b.a5eed8"]]},{"id":"d5d50c16.bcd7e","type":"batch","z":"6bf9fb85.abde3c","name":"","mode":"count","count":"2","overlap":0,"interval":10,"allowEmptySequence":false,"topics":[],"x":626,"y":504,"wires":[["eaf46429.a6f038"]]},{"id":"eaf46429.a6f038","type":"join","z":"6bf9fb85.abde3c","name":"","mode":"auto","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":746,"y":504,"wires":[["c670b1c5.8eee38"]]},{"id":"c670b1c5.8eee38","type":"function","z":"6bf9fb85.abde3c","name":"","func":"m = msg.payload\n\ncombined = m[0].concat(m[1])\n\nreturn {payload:combined}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":876,"y":504,"wires":[["5f358519.1fec34"]]},{"id":"5f358519.1fec34","type":"csv","z":"6bf9fb85.abde3c","name":"","sep":",","hdrin":"","hdrout":"all","multi":"one","ret":"\\n","temp":"first,last,street,city,state,postcode","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":1010,"y":504,"wires":[["b18add9e.c07308"]]}]

```

The idea; read 2 csv files, use a batch + join node to create an array of objects, merge them and convert back to csv.

---

<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: [31 August 2020 12:30 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248/3 "2020-08-31T12:30:30Z")

</div>

I think it might be worth your while explaining what you are doing with the csv files in this thread and [the previous one](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/). Are you using the csv files just for temporary storage? If so then there are probably much easier ways of solving your problems.

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [31 August 2020 12:45 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248/4 "2020-08-31T12:45:11Z")

</div>

It works perfect, could you clarify what the join and batch node is used for?

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [31 August 2020 12:49 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248/5 "2020-08-31T12:49:29Z")

</div>

Yes, it is to save temporary data, I have values ​​in the plc that are updated and crushed every 8 hours, the idea is to record the values ​​of these variables within those 8 hours through the pulses of the 2 Boolean inputs, which are the ones that tell me to record when the data has changed, when 8 hours pass, I merge the 2 csv into one and delete them, and once merged, I send the resulting csv by email to be able to see the data of the 2 variables registered, I don't know if I have explained myself clearly.

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [31 August 2020 12:55 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248/6 "2020-08-31T12:55:27Z")

</div>

When I have everything working, I will upload a capture and the flow in case it is of interest to a colleague.

---

<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: [31 August 2020 14:31 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248/7 "2020-08-31T14:31:25Z")

</div>

> [@osancleca](#):
>
> Yes, it is to save temporary data,

You could use persistent context instead, almost certainly that would be simpler.  
[https://nodered.org/docs/user-guide/context](https://nodered.org/docs/user-guide/context)

---

<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: [30 October 2020 14:31 UTC](https://discourse.nodered.org/t/how-to-merge-multiple-csv-into-one/32248/8 "2020-10-30T14:31:38Z")

</div>

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