I'm looking for help to parse this text file. I have this sample part of the file. It’s like a list of names in a file that I like to turn into a CSV file. It looks like this:
Membership Date: Jan 1, 1999
Sponsors: Mary Muray, Judy White,
Ronald Zurch,
Nina Lin,
Nathan Garton,
Howard Ross
Comments: This are great members to have on our team.
Here is the expected output with quotes (“):
“Membership Date: Jan 1, 1999",
"Sponsors: Mary Muray, Judy White, Ronald Zurch, Nina Foss, Nathan Garton, Howard Ross“,
“Comments: This are great members to have on our team.”
Note that the output has 3 fields. And the sponsor field has the line feeds taken out, so all names are in one field.
My code looks like this:
val filename: String = "/data/members.csv"
val lines = Source.fromFile(filename).getLines().toList
val ToLines = lines.dropWhile(line => !line.startsWith("Sponsor: ")).takeWhile(line => !line.startsWith("Comments: ")).toSeq
The last line of code places each name in each element in the sequence, any line is placed into its own separate element in the list. I need help to get all names to be in a single element, so when I save the results as a CSV, the sponsor field has all its names in one field. Let me know if this does not make sense.