Group Lines Based on Similar Attributes

I have some text that I want to sort and group based on value after 'her name is' or 'his name is'.

I have attached an input.txt file and an output.txt file since it's easier to explain that way.

Some key notes: The input file will be consistent but will have tons of lines and data; so the Groups should be able to increment.

Appreciate your help!
input.txt
output.txt
deharvyAsked:
Who is Participating?
 
Michael701Commented:
Ok, let's start this way.

Can you break the problem into parts, in English?

ie

Read each line in the input file.
Find the person's name (first word on the line)
Find the Objects name (last word on the line)
...
...
...


0
 
Michael701Commented:
Wow, it's almost like I'm in school again.

Whereas we discourage have EE members do your entire homework assignment. We are more than happy to assist when you're stuck on a specific problem.

Do you have a specific question?

Like "How do I find the name after the text 'her name is' or 'his name is'?

0
 
deharvyAuthor Commented:
I know this will entail arrays and foreach statements, but I don't know where to start; new to this sort of thing.

As for a specific question..... can you provide the code that can provide the results in output.txt? I know that's not what you wanted to hear.
0
 
Michael701Commented:
As for a specific question..... can you provide the code that can provide the results in output.txt? I know that's not what you wanted to hear.

ok, now "I know that's not the code what you wanted to see."


echo "Group 1\n";
echo "Peter has a sister and her name is Mindy. \n";
echo "Mindy has a dog and his name is Pluto.\n";
echo "Pluto has a girlfriend and her name is Venus.\n";
echo "------------------------\n";
echo "Group 2\n";
echo "Gary has a girlfriend and her name is Jasmin.\n";
echo "Norbit has a sister and her name is Candy. \n";
echo "Candy has a dog and his name is Gary.\n";

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.