How to split a line into multiple lines?

后端 未结 1 789
挽巷
挽巷 2020-12-22 08:52

I have a CSV file which looks something like this:

Column1,Column2,Column3
John,Smith,\"AA, AH, CA, NI, PB\"
Regin         


        
相关标签:
1条回答
  • 2020-12-22 09:32

    Use Import-Csv to read the input file, then split the third column and create new output lines for each resulting element:

    Import-Csv 'C:\path\to\input.csv' | ForEach-Object {
      foreach ($value in ($_.Column3 -split ', ')) {
        $_ | Select-Object -Exclude Column3 -Property *,@{n='Column3';e={$value}}
      }
    } | Export-Csv 'C:\path\to\output.csv' -NoType
    

    The Select-Object construct replaces the existing property Column3 with a new property Column3 that contains only a single value.

    0 讨论(0)
提交回复
热议问题