I have a file called one_to_many.txt. In the file is the data:
a,aaa
b,bbb
c,ccc
I want to use powershell to create 3 files a.txt, b.txt and c.txt
File a.txt to contain data “aaa”, b to contain “bbb …
I’m new to Powershell and can’t work out how to do it. Thanks.
One possible solution:
Get-Contentreads the file and returns lines, one by one. Each line is piped toForeach-Objectwhere it can be accessed as$_.You need to split the line by comma, so invoke operator
-splitwhich returns in this case array of 2 items. The assignment$filename, $content = ..causes that content of first item in array (from-split) is assigned to$filenameand the rest to `$content.Then simply store that content in the file via
Set-Content