Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Powershell Script, how do I convert a pipe '|' delimited file to a comma ',' delimited CSV?

In Powershell Script, how do I convert a | (pipe) delimited CSV file to a , (comma) delimited CSV file?

When we use the following command in Windows Powershell Encoding 'UTF8' -NoType to convert from | (pipe delimiter) to , (comma delimiter), the file is converted with , delimited but the string was surrounded by " " (double quotes). Like given below:

Source file data:

ABC|1234|CDE|567|

Converted file data:

"ABC","1234","CDE","567",

I want to generate the following:

ABC,1234,CDE,567,

What command can I use to convert the delimiter from | to ,?


1 Answers

I would use:

(Get-Content -Path $file).Replace('|',',') | Set-Content -Path $file
like image 142
E. Jaep Avatar answered Dec 01 '25 01:12

E. Jaep