I have a requirement to add data to the last column of a CSV file. The test file I have looks like:
NAME,AGE,OFFICE,DEPT,SKILL jack,24,IBM,Retail tom,32,MS,BFSI SAM,44,MGR,Test
I have managed to parse the CSV but then adding data to the last column "SKILL" is difficult. The requirement is to add the word 'Java' to the last column on each row
NAME,AGE,OFFICE,DEPT,SKILL jack,24,IBM,Retail,Java tom,32,MS,BFSI,Java SAM,44,MGR,Test,Java
Please note that the value added to the last column remains the same across rows.
You can change the value of
SKILL
property of the imported objects, and export to CSV file by this:However
Export-Csv
adds quotation marks around the values, sotest_out.txt
would look like this:Maybe you should simply add
",Java
" to the end of each line second line onwards:You could simply create an object that contains the current csv-data and extend that object with the string
Java
like so: