Parse data from a text

Hello,

I created a workflow with a http request. The response of this request give me the following text:
192.168.1.2,8/9/2022 1:00 AM,8/10/2022 1:00 AM,293,293,293,YELLOW,< 0.1%,0,
192.168.4.5,8/9/2022 2:00 AM,8/10/2022 1:00 AM,245,245,245,YELLOW,0.4%,0,
192.168.2.1,8/9/2022 1:00 AM,8/10/2022 1:00 AM,938,938,938,YELLOW,< 0.1%,0,
192.168.6.1,8/9/2022 1:00 AM,8/10/2022 1:00 AM,6190,6183,6182,YELLOW,< 0.1%,0,Abuse reported for: [email protected],
192.168.1.6,8/9/2022 1:00 AM,8/10/2022 1:00 AM,6131,6125,6124,YELLOW,< 0.1%,0,Abuse reported for: [email protected],

I would like to be able to split each line, and in each line each object. For example, I would like to be able to recover the data “293” from the IP “192.168.1.2” (first line)
Is it possible?

Thanks a lot,
Julien

Hi @julien1

There will be some parts to this proces. the best way to extract the data from the text will depend on the structure of it. Is there a line break there? When I coppy it there is a “\n” included as a line break resulting in this:

If you put this behind your actual http request does it provide you with the items as intended?
After that you can process the individual items.

Hey @BramKn

Thanks a lot for your answer. It seems that there is a line break, but not a “/n” included… So it doesn’t work :(.

If you use split(‘,’) the output might show you what linebreaks are there.

Would also be a possible starting point for another solution if there is no actual linebreak.

1 Like

Sorry @BramKn I tried again with {{ $json[“sample”].split(“\n”) }} and it works perfectly!
Do you know how I could separate now each data of each line? :slight_smile:

It shouldnt be too difficult do you have column names for them all?

I think the IP could be the column name

You only need the IP?

No, for each line I need the IP, the color and the data just after the color.

Hi @julien1

Like this?
You can combine set nodes but this makes it a bit more clear what is going on.

Hey @BramKn , thanks a lot, I can see all the datas well parsed now.
The issue now is when I want to put each set in a Google Sheet document, I can only see the first set.
Do you know what I forget to do?

Thanks,
Julien

Sorry @julien1
I do not understand what you are trying to do.

@BramKn I’m trying to fill up this Google Sheet:

And what is not working?
Can you show the workflow you got now?

I have the same workflow that you sent.

I can only retrieve the first line: 192.168.1.2, Yellow, no comment.

I can’t retrieve the line 2 for example (192.168.4.5, Yellow, no comment).

Hi @julien1

This node is good. Its about the node going after it.
For adding rows in google sheet (or any sheet) you need seperate items (records) and seperate columns.
You got that.
So it looks like something isnt set correct after this node.

@BramKn
I’m sorry, I guess I’m not expressing my problem well.
When I put in a Google Sheet with the correct column names etc, the data fills in fine. The problem is that they all fill up: I have one row per data. I would like to be able to choose the row I want to display only (for example row 6 for the IP 192.168.1.6, Yellow, Abuse reported for: [email protected].

Is this clearer? :slight_smile:
I can’t share the workflow directly because it contains a work sheet document.

You can use the if node to filter out which rows you want to add.

It works. Thanks a looooot!!! You’re amazing.

1 Like