# Pull line number from text

**URL:** <https://discourse.nodered.org/t/pull-line-number-from-text/37783>\
**Category:** General\
**Created:** [20 December 2020 03:47 UTC](https://discourse.nodered.org/t/pull-line-number-from-text/37783 "2020-12-20T03:47:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [20 December 2020 03:47 UTC](https://discourse.nodered.org/t/pull-line-number-from-text/37783/1 "2020-12-20T03:47:58Z")

</div>

Hi all,

Im sure this is really simple but I couldn't find anything in search that was helpful.

I have a string returned from a solar inverter

1  
1  
EAB961770026  
QRGQQBWVVXSTTVYP  
M11  
17511-708R+17511-707R  
11:45 20/12/2020  
0  
1  
BS30000101770043  
2225  
8.8  
OK  
Error

I just want to pull out lines 11 and 12

I tried using a sort node but it didnt seem to put them all into an array

Can somebody give me some hints?

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [20 December 2020 04:48 UTC](https://discourse.nodered.org/t/pull-line-number-from-text/37783/2 "2020-12-20T04:48:32Z")

</div>

How is this string getting into NR ? Serial port read, etc etc ?

Might be an idea to post up a debug shot as well for some ideas (as there may be a more elegant way)

The string object is the way to get it if it is a contained in a single message

Craig

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [20 December 2020 05:57 UTC](https://discourse.nodered.org/t/pull-line-number-from-text/37783/3 "2020-12-20T05:57:39Z")

</div>

Hi Craig,

here is the debug

the string is acquired thru a http request

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7c47483c4dbc0c1028ba1b9ecaff9f23db0c7654.png)

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [20 December 2020 06:16 UTC](https://discourse.nodered.org/t/pull-line-number-from-text/37783/4 "2020-12-20T06:16:17Z")

</div>

OK looks fairly straightforward.

Try and feed it into the String command which should be able to treat it as individual lines - have a look at the help for the string node as it gives all the options and well documented

Craig

---

<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 December 2020 07:42 UTC](https://discourse.nodered.org/t/pull-line-number-from-text/37783/5 "2020-12-20T07:42:05Z")

</div>

split the string using a function node and JS, or change node and JSONata

example of JSONata

```auto
[{"id":"a0f0ceca.b3f5f","type":"inject","z":"8d22ae29.7df6d","name":"Trigger Manual","props":[{"p":"payload"},{"p":"random","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":2900,"wires":[["f28bcdf4.04cb4"]]},{"id":"f28bcdf4.04cb4","type":"template","z":"8d22ae29.7df6d","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"1\n1\nEAB961770026\nQRGQQBWVVXSTTVYP\nM11\n17511-708R+17511-707R\n11:45 20/12/2020\n0\n1\nBS30000101770043\n2225\n8.8\nOK\nError","output":"str","x":140,"y":2960,"wires":[["83a42de1.ce546"]]},{"id":"83a42de1.ce546","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"($value := $split(payload, \"\\n\");\t{\"value1\":$value[10], \"value2\":$value[11]})","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":2920,"wires":[["e865d4e9.d0217"]]},{"id":"e865d4e9.d0217","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":2900,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 December 2020 10:11 UTC](https://discourse.nodered.org/t/pull-line-number-from-text/37783/6 "2020-12-20T10:11:45Z")

</div>

> [@leftymuller](#):
>
> Can somebody give me some hints?

Use a function node...

```auto
var lines = msg.payload.split("\n");
msg.payload = {
  line11: lines[10],
  line12: lines[11],
}
return msg;

```

---

<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:** [18 February 2021 10:11 UTC](https://discourse.nodered.org/t/pull-line-number-from-text/37783/7 "2021-02-18T10:11:59Z")

</div>

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