Import-CSV | Export-CSV split out fields

So I’d like to import that csv, and then export a csv with each of the foods as a separate record for each person.

CSV Example:

id, person_name, food1, food2, food3, food4
1,Tim,Spinach,Spam, Bolonga, Pasta
2,Rich,Cake,Onions,Tomatoes,Spinach
3,Ann,Salad,Pasta,

Example output:

1,Tim,Spinach
1,Tim,Spam
1,Tim,Bologna
1,Tim,Pasta
2,Rich,Cake

Ideas? Assuming this won’t be a simple one-liner.

Raze,
Welcome to the forum. :wave:t3:

What have you tried so far?

This forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

Regardless of all that … your input CSV looks weird. Why are the foods in different columns? I’d expect them to be as list in one column. Especially when there are empty cells.