Powershell import-csv conditional for column -


i'm trying find best way using powershell modify row in csv based on following condition:

if column test contains word,word following:  1) copy entire row once keep first word in column test  2) copy entire row again keep second word in column test  3) delete original row had word,word in column test 

example:

subject~school~test~code~year math~padf~true,false~0943~2016 

i'd like:

subject~school~test~code~year math~padf~true~0943~2016 math~padf~false~0943~2016 

i'm no expert in powershell, playing around using import-csv, , using get-content foreach-object, it's not working. if knows of easier way or solution case above, fantastic!

thank you

knows of easier way or solution case above

with programming, there's no such thing 'the' solution. write want (good steps 1,2,3 in question) , make code that:

import-csv d:\data.csv -delimiter '~' | foreach-object {      if ($_.test -match ',')                  # if row.test contains comma     {         $first, $second = $_.test.split(',') # first , second words ready          $_.test = $first                     # output record once          $_                                   # first word          $_.test = $second                    # , again second word         $_                                   #     }     else      {         $_                                   # otherwise output unchanged     } } | export-csv out.csv -delimiter '~' -notypeinformation 

not entirely sure mean delete, run , export-csv out.csv -delimiter '~' -notypeinformation , output new file without original word,word row.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -