cmoerbe
asked on
Add commas to text file and save as .csv using Powershell
I am trying take a text file that looks like this:
Column
Item 1
Item 2
Item 3
and make it look like this in .CSV format
Column,
Item1,Item2,Item3
When I try CovertTo-CSV I get output such as:
#Type System.string
"Length"
"4"
"8"
"7"
etc.
Can someone please advise?
Thanks!
Column
Item 1
Item 2
Item 3
and make it look like this in .CSV format
Column,
Item1,Item2,Item3
When I try CovertTo-CSV I get output such as:
#Type System.string
"Length"
"4"
"8"
"7"
etc.
Can someone please advise?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, can't follow you.
Based on your example, the text file you have seems to be a csv already - a header line and some rows with items. It's a csv with only one column, but a csv nevertheless.
Based on your example, the text file you have seems to be a csv already - a header line and some rows with items. It's a csv with only one column, but a csv nevertheless.
ASKER
actually its not including commas at all i see
With only one column, there are no fields to separate, hence no field separator. If there were a comma at the end, it would indicate a second column without data in it, and a missing column header.
Just run an "Import-Csv" on the file content you posted - you'll get an array of objects with one property, "Column".
Just run an "Import-Csv" on the file content you posted - you'll get an array of objects with one property, "Column".
ASKER
Your code worked as expected. Thank you for the help!
ASKER
Thanks for the advice!
ASKER
Which I assume would keep all the data in one column under the header?
Column1,
Item1,
Item2,
Item3,