Extract data from text-file

Hello community,
I’m trying to build a contact tiddler, where the data is extracted from a simple textfile. The data format is given, because I create the textfile with a simple cut&paste-operation and I don’t like to reformat it to save time.
What I managed so far is to split the textfile line by line. Unfortunately, there are some keywords on one line (like ‘room’ or ‘phone’) and the data is on the next line.

Max Headroom
virtual

Information
    Employee Role A
Department

        Domain: Domain-Name
        Department: Department-Name
        Team: Team-Name

Room:
    Room-Number
TL-KW:
    Short-Code
Mobile:
    Mobile-Phone-Number
Phone:
    Phone-Number

What I’m trying to achieve:
Get the keyword AND the data for further processing.

It would work easily when re-formatting the text like:

Room:    Room-Number
TL-KW:    Short-Code
Mobile:    Mobile-Phone-Number
Phone:    Phone-Number

But this is something I’m trying to avoid and I’m wondering if there is another solution for my problem.
Is there a way to process this with a ListWidget?

Any help is very appreciated, thank you in advance.

I’m too tired to go deeper but my spontaneous thought is that you can run it through a wiki filter (which is maybe what you already do to split it into lines?) but instead split it at the keywords. I think you could enter the keywords into a listwidget, and give them the variable name keyword and then nest in another listwidget where you split<keyword> or some such.

…but I’m sure others can give better replies.

1 Like

You could pass your text through a filter that strips out all newlines that immediately follow a colon, like this:

[search-replace:g:regexp[:\n],[:]]

see https://tiddlywiki.com/#search-replace%20Operator

Let me know how it goes…

-e

1 Like

That’s another approach, which I didn’t think of.
Sometimes i can’t see the wood for the trees :wink:

Very useful, thank you, Eric!

I think that a combination of @twMat and @EricShulman suggestion will suit me best: Split the text file in two parts and analyse the first part using the counter attribute of the ListWidget to determine which line I’m on.
Getting the keywords and values onto one line, using Erics suggestion, will be the second part.

Thanks to both of you!