View Single Post
Old 08-09-2007   #3 (permalink)
Shay Levi
Guest


 
 

Re: Modify CSV, add fields

Note that Import-Csv imports comma-separated value items, so replace
";" with a comma.


Shay
http://scriptolog.blogspot.com



> Try this:
>
> $csv = import-csv .\test.csv
> $csv
> $csv | add-Member -memberType noteProperty -name Field6 -value ""
> -force;
> $csv | gm
> # you should see a new note property names field6
> $csv | % {$_.Field6 = $_.Field1+$_.Field2}
> $csv
> Shay
> http://scriptolog.blogspot.com
>> Hello,
>>
>> I start with PS, and ... hum, difficult for me
>>
>> I have a CSV file, like this :
>>
>> Field1;Field2;Field3;Field4
>> John;PATTY;555-12345;NY
>> Homer;MAC CULLY;555-32147;NH
>> Selma;BOUVIER;555-12378:KS
>> And i want to parse and modify it, this is the target :
>> Field0;Field1;Field2;Field3;Field4;Field5
>> John PATTY;John;PATTY;555-12345;NY;JP
>> Homer MAC CULLY;Homer;MAC CULLY;555-32147;NH;HM
>> Selma BOUVIER;Selma;BOUVIER;555-12378;KS;SB
>> So, add two fields which are given by other fields in the CSV
>> Field0 = Field1 + Field2
>>
>> Field5 = Initials of Field0
>>
>> Shall i use import csv ? Or can i use a foreach command piped with a
>> type MyFile.csv ?
>>
>> Thanks for you help.
>>
>> --
>> P.A.



My System SpecsSystem Spec