"grep" words from /var/log/messages

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

[{"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"]]}]

please fix your code :smile: It has to go between the backticks. I think you pasted it outside :see_no_evil:

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

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

m


Click where arrow 1 points, than paste your code where arrow 2 points

Sorry man !! fixed it
m

1 Like

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

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

[{"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"]]}]

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...

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