# "grep" words from /var/log/messages

**URL:** <https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912>\
**Category:** General\
**Created:** [2 May 2020 08:59 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912 "2020-05-02T08:59:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![menno](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@menno](https://discourse.nodered.org/u/menno)\
**Post date:** [2 May 2020 08:59 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/1 "2020-05-02T08:59:16Z")

</div>

Hi all

i am busy to get some special data from my /var/log/messages file

this is the line that i am interested in:  
_May 2 10:52:23 mw-pi-star root M: 2020-05-02 08:52:23.188 Linked to PARROT_

i just want to have this line and only the text "Linked to PARROT"  
i played around with the "string" function but was not able to figure it out.  
Can please someone help me ?

the goal is to put these words in an new html file on my webserver.  
**many thanks in advance**  
m

the code

```auto
[{"id":"9b70cde6.e3ad5","type":"tab","label":"ExternalRadio","disabled":false,"info":""},{"id":"34dbb600.74461a","type":"debug","z":"9b70cde6.e3ad5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":140,"wires":[]},{"id":"1de32ca2.2d2c93","type":"tail","z":"9b70cde6.e3ad5","name":"","filetype":"text","split":"[\\r]{0,1}\\n","filename":"/var/log/messages","inputs":0,"x":210,"y":140,"wires":[["5fcced21.b7c254"]]},{"id":"5fcced21.b7c254","type":"string","z":"9b70cde6.e3ad5","name":"","methods":[{"name":"between","params":[{"type":"str","value":"Linked to"},{"type":"str","value":"\\n"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":430,"y":180,"wires":[["34dbb600.74461a"]]}]

```

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [2 May 2020 09:25 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/2 "2020-05-02T09:25:27Z")

</div>

please fix your code 😄 It has to go between the backticks. I think you pasted it outside 🙈

---

<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:** [2 May 2020 09:26 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/3 "2020-05-02T09:26:43Z")

</div>

> [@menno](#):
>
> May 2 10:52:23 mw-pi-star root M: 2020-05-02 08:52:23.188 `

Since there is a single period character (`.`) you could split the line on that and end up with `188 Linked to PARROT`. You could then split that on the first space and end up with `Linked to PARROT`

---

<div class="post-metadata">

**Author:** ![menno](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@menno](https://discourse.nodered.org/u/menno)\
**Post date:** [2 May 2020 09:44 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/4 "2020-05-02T09:44:01Z")

</div>

is the code better now ??  
i used the "blockquote"

m

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [2 May 2020 09:47 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/5 "2020-05-02T09:47:32Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/cad3bd2f7e9879eff6e1caeb001d182c49c5e7ed.jpeg)  
Click where arrow 1 points, than paste your code where arrow 2 points

---

<div class="post-metadata">

**Author:** ![menno](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@menno](https://discourse.nodered.org/u/menno)\
**Post date:** [2 May 2020 09:52 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/6 "2020-05-02T09:52:14Z")

</div>

Sorry man !! fixed it  
m

---

<div class="post-metadata">

**Author:** ![menno](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@menno](https://discourse.nodered.org/u/menno)\
**Post date:** [2 May 2020 10:12 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/7 "2020-05-02T10:12:20Z")

</div>

sorry can not get it to work  
i attached a debug node on it and see all the lines ..  
i just want to see 1 output in the debug node containing the line "Linked to"

there is not a "grep" node available ??  
m

---

<div class="post-metadata">

**Author:** ![menno](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@menno](https://discourse.nodered.org/u/menno)\
**Post date:** [2 May 2020 10:54 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/8 "2020-05-02T10:54:37Z")

</div>

very very dirty way found ...

there must be a better way to do it to filter this line out  
_May 2 12:51:33 mw-pi-star root M: 2020-05-02 10:51:33.486 Linked to PARROT_  
with the result : _Linked to PARROT_

i came up with this  
can you please help me out with a better way to do this ??

many thanks in advance  
m

my code

```auto
[{"id":"34dbb600.74461a","type":"debug","z":"9b70cde6.e3ad5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1330,"y":100,"wires":[]},{"id":"1de32ca2.2d2c93","type":"tail","z":"9b70cde6.e3ad5","name":"","filetype":"text","split":"[\\r]{0,1}\\n","filename":"/var/log/messages","inputs":0,"x":170,"y":100,"wires":[["cbe1568c.a44f98"]]},{"id":"cbe1568c.a44f98","type":"function","z":"9b70cde6.e3ad5","name":"Linked to","func":"if (msg.payload.includes(\"Linked to\"))\n{\n return msg;\n}\n","outputs":1,"noerr":0,"x":400,"y":100,"wires":[["4b7ec665.119e48"]]},{"id":"4b7ec665.119e48","type":"split","z":"9b70cde6.e3ad5","name":"","splt":".","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"payload","x":570,"y":100,"wires":[["ac745e6a.1ff8c"]]},{"id":"ac745e6a.1ff8c","type":"function","z":"9b70cde6.e3ad5","name":"Linked to","func":"if (msg.payload.includes(\"Linked to\"))\n{\n return msg;\n}\n","outputs":1,"noerr":0,"x":760,"y":100,"wires":[["ea95c567.ef19c8"]]},{"id":"ea95c567.ef19c8","type":"string","z":"9b70cde6.e3ad5","name":"","methods":[{"name":"delLeftMost","params":[{"type":"str","value":" "}]},{"name":"trimRight","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":970,"y":100,"wires":[["34dbb600.74461a"]]}]

```

---

<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:** [2 May 2020 11:30 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/9 "2020-05-02T11:30:49Z")

</div>

I could give you the solution but let me give you soem hints first.  
1 - use a `switch` node to check if the msg _ **contains** _ the string  
2 - use the `string` node and try one or two 'delLeftMost' rules

reduces the flow to four nodes from six...

---

<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:** [1 July 2020 11:30 UTC](https://discourse.nodered.org/t/grep-words-from-var-log-messages/25912/10 "2020-07-01T11:30:53Z")

</div>

Closed on 1 July 2020 11:30 UTC

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