# Parsing txt file

**URL:** <https://discourse.nodered.org/t/parsing-txt-file/9721>\
**Category:** General\
**Created:** [3 April 2019 09:11 UTC](https://discourse.nodered.org/t/parsing-txt-file/9721 "2019-04-03T09:11:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SmartCanteen](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@SmartCanteen](https://discourse.nodered.org/u/SmartCanteen)\
**Post date:** [3 April 2019 09:11 UTC](https://discourse.nodered.org/t/parsing-txt-file/9721/1 "2019-04-03T09:11:44Z")

</div>

## Hello there , I am new to Node-red and I`d like to know how do I can parse text from a file and display it on my dashboard ... My dashboard is ready and working but idk how to parse the "Menu1" word from my txt file ... the first node that opens the file works (the entire content of the file appears in the debug) but still cant parse a word in ... Here is the code in my parsing node ;

if (!context.count){  
context.count = 20;  
}  
parsed = parseInt(msg.payload);  
if(parsed==1){  
context.count++;  
}

msg.payload = context.count;  
return msg;

* * *

## and here is the debug tab :

03/04/2019 à 11:02:45node: 9fb6b5f3.404608  
msg.payload : string[29]  
"Menu1 \t fasfdfds \t fghsd \t"  
03/04/2019 à 11:02:45node: 40c35d07.249254  
msg.payload.variable\_1 : undefined  
undefined

## as you can see , it can read in the file but dont recognise the word "Menu1" in it.. Thanks for help and spending your time reading this

## here is the parsing flow :

[{"id":"9aed556e.760008","type":"tab","label":"parse","disabled":false,"info":""},{"id":"b2db9145.f5b1","type":"inject","z":"9aed556e.760008","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":420,"y":80,"wires":[["a3ab124e.5f21a"]]},{"id":"a3ab124e.5f21a","type":"file in","z":"9aed556e.760008","name":"access to file","filename":"/home/pi/Desktop/sms/messages","format":"utf8","chunk":false,"sendError":true,"encoding":"utf8","x":170,"y":180,"wires":[["9fb6b5f3.404608","a8c43f28.32aed"]]},{"id":"881d70a9.606ec","type":"function","z":"9aed556e.760008","name":"recherche du mot Menu1","func":"if (!context.count){\n context.count = 20;\n}\nparsed = parseInt(msg.payload);\nif(parsed==1){\n context.count++;\n }\n\nmsg.payload = context.count;\nreturn msg;\n","outputs":1,"noerr":0,"x":510,"y":160,"wires":[]},{"id":"40c35d07.249254","type":"debug","z":"9aed556e.760008","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.variable\_1","targetType":"msg","x":450,"y":360,"wires":},{"id":"9fb6b5f3.404608","type":"debug","z":"9aed556e.760008","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":370,"y":40,"wires":},{"id":"a8c43f28.32aed","type":"function","z":"9aed556e.760008","name":"parsing "Menu1"","func":"if (!context.count){\n context.count = 20;\n}\nparsed = parseInt(msg.payload);\nif(parsed==1){\n context.count++;\n }\n\nmsg.payload = context.count;\nreturn msg;\n","outputs":1,"noerr":0,"x":330,"y":260,"wires":[["40c35d07.249254"]]}]

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [3 April 2019 09:51 UTC](https://discourse.nodered.org/t/parsing-txt-file/9721/2 "2019-04-03T09:51:20Z")

</div>

I’m on my phone so can’t import your flow.

But assuming your parsing node is a function, you aren’t using the newer syntax for context values.

See  
[https://nodered.org/docs/writing-functions#storing-data](https://nodered.org/docs/writing-functions#storing-data)

You can also see the Logging events part of the same page [https://nodered.org/docs/writing-functions#logging-events](https://nodered.org/docs/writing-functions#logging-events) for how to log events from within a function so you can see what your function is doing

---

<div class="post-metadata">

**Author:** ![SmartCanteen](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@SmartCanteen](https://discourse.nodered.org/u/SmartCanteen)\
**Post date:** [3 April 2019 10:07 UTC](https://discourse.nodered.org/t/parsing-txt-file/9721/3 "2019-04-03T10:07:53Z")

</div>

> [@ukmoose](#):
>
> you aren’t using the newer syntax for context values.

yes thanks , but i dont really know what I should use ,Im a very beginner with node-red

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [3 April 2019 10:09 UTC](https://discourse.nodered.org/t/parsing-txt-file/9721/4 "2019-04-03T10:09:56Z")

</div>

Which is why I posted a link to the docs that include examples

---

<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:** [3 April 2019 15:30 UTC](https://discourse.nodered.org/t/parsing-txt-file/9721/5 "2019-04-03T15:30:01Z")

</div>

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…
