# Read CSV file and Replace the name of a variable

**URL:** <https://discourse.nodered.org/t/read-csv-file-and-replace-the-name-of-a-variable/39465>\
**Category:** General\
**Created:** [20 January 2021 20:20 UTC](https://discourse.nodered.org/t/read-csv-file-and-replace-the-name-of-a-variable/39465 "2021-01-20T20:20:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Roger](https://discourse.nodered.org/u/Roger)\
**Post date:** [20 January 2021 20:20 UTC](https://discourse.nodered.org/t/read-csv-file-and-replace-the-name-of-a-variable/39465/1 "2021-01-20T20:20:40Z")

</div>

Hi all,

I have thounsands of sensors which has his deveui (identificator) with numbers like 54-23-12-54.... In a csv file I have in the first colum this deveui and in the second the name that I want to put at my sensor. Somebody has an idea or example related on how I can do it. The steps I'm thinking about are read the csv, do something to know if the deveui of the first column exists and change the name if yes, but I don't know how to do this process.

It's the same that change node, but I have a lot of sensors and I don't want to put this charge on node red.

Thank you,  
Roger.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [20 January 2021 21:26 UTC](https://discourse.nodered.org/t/read-csv-file-and-replace-the-name-of-a-variable/39465/2 "2021-01-20T21:26:22Z")

</div>

If i under stand you could just use array.map() in a function node to check all col1's, and change if needed.  
i.e.

```auto
[{"id":"5ad7b371.e3aa7c","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"search","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":2000,"wires":[["fa632041.9888a8"]]},{"id":"fa632041.9888a8","type":"template","z":"57675e72.26a0d8","name":"simulate csv","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"dname1,newname1,more\nname1,newname1,more\ndname2,newname2,more\nname2,newname2,more\n","output":"str","x":440,"y":2000,"wires":[["ee3daed8.93c5a8"]]},{"id":"ee3daed8.93c5a8","type":"csv","z":"57675e72.26a0d8","name":"","sep":",","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":210,"y":2060,"wires":[["3465403.2c9b8c"]]},{"id":"3465403.2c9b8c","type":"function","z":"57675e72.26a0d8","name":"","func":"let search =\"dname\";\nmsg.payload = msg.payload.map(v => (v.col1.substr(0,search.length) === search) ? Object.assign(v,{\"col1\":v.col2}) : v);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":2060,"wires":[["25013c10.49587c"]]},{"id":"25013c10.49587c","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":2000,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Roger](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Roger](https://discourse.nodered.org/u/Roger)\
**Post date:** [20 January 2021 21:36 UTC](https://discourse.nodered.org/t/read-csv-file-and-replace-the-name-of-a-variable/39465/3 "2021-01-20T21:36:34Z")

</div>

Thank you E1cid, I'm going to try in this way.

---

<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:** [21 March 2021 21:36 UTC](https://discourse.nodered.org/t/read-csv-file-and-replace-the-name-of-a-variable/39465/4 "2021-03-21T21:36:35Z")

</div>

Closed on 21 March 2021 21:36 UTC

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