How to separate sorte different characters from one textfile and copy them in a new textfile?

My first post, so don't kill me :slight_smile:

Say i open some textfile with some example like this.

on the table are handy, bread and wine

Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this:

table

plane      = airbus
car        = vw
electronic = handy
eat        = bread
drink      = wine

Which is the best way to handle it with awk,grep,...,

Sorry, but i don't get what you want to do.

I understand you have one file with an assortment of things (handy (which is "mobile" or "cell phone" in english, btw.), bread and wine), correct?

I understand you have a second file with a structure that looks similar to what is commonly called "stanza-format":

entry1:
     item1=value1
     item2=value2
     item3=value3
     [...]

entry2:
     item1=value4
     item2=value5
     item3=value6
     [...]
[...]

Is this correct? If not: where did i go wrong? If so: what do you want to do now?

I hope this helps.

bakunin

I read your edit from my first post, thx.

The names of the things are just placeholders so just ignore them, it could be
everything but i always know what is in. Important is, that the first file have
only one sentence with words or numbers and i want to separate and list them
into the secondfile or it could also be new file.

I thought maybe something like this to grab the first file:

grep "table " test.txt |awk -F: '{print $5, $6, $8}'  

And after that sort the grabbed to a new or already existing file that look like
the list above.

hmm: if you already know what it is that you are looking for you do not need to search for it in first place, no? Say, you know that the three items are "handy", "bread" and "wine". Why would you need to search for them in the first file if you already know them?

I could understand you need to search if you know something like "its always the third word in the second line" and you are interested in its value, like "bread" or - the next time - "wine". But to search for "bread" only makes sense if there are two possibilities: the word is there or it is not. If it is guaranteed to be there searching for it makes simply no sense, no?

OK, but in your example you have 3 items: "handy", "bread" and "wine". Where do the other two lines:

plane      = airbus
car        = vw

come from? And where do the categories of the items come from? Why is the finding of "handy" triggering a line like

electronic = handy

? From where should the computer know that "handy" is an electronic device?

Please explain - in a non-technical manner - what you are trying to do and what the outcome should be like. It might help to take a step back and - instead of concentrating on the method - first work out and cleanly define the requirements.

I hope this helps.

bakunin