Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell create file for each distinct record

Tags:

powershell

Working with large CSV file as shown below... Need to loop and create file for each distince AppID i.e below would have three files for AppID 1,3 and 5. Any help to do this with powershell would be appreciated. Thank you.

Col1   | AppID
data11 | 1
data12 | 1
data13 | 1
data31 | 3
data32 | 3
data51 | 5
data52 | 5
like image 526
user2029947 Avatar asked Apr 08 '26 19:04

user2029947


1 Answers

Assuming you want to use the bar as a delimiter, then this should work:

import-csv .\foo.csv -Delimiter '|' | group-object appid | foreach-object {
    $_.group | Export-Csv "appid_$($_.name).csv" -NoTypeInformation }

Hope this helps.

like image 104
x0n Avatar answered Apr 11 '26 09:04

x0n



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!