abhishek pandey
abhishek pandey

Reputation: 93

how to convert from Newline Delimited text file to csv with Powershell

I have a text file containing the below test data:

1234
\\test
QATest
Silk
Chrome

I have a requirement to convert this text file into a CSV file using Powershell which would look somewhat like

1234,\\test,QATest,Silk,Chrome

Could anybody please suggest the right way?

Upvotes: 0

Views: 958

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

Read all the lines in, then concatenate them using the -join operator:

$originalLines = Get-Content .\input.txt
$originalLines -join ',' |Set-Content .\output.csv

Upvotes: 2

Related Questions