Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting txt file to csv in powershell

Tags:

powershell

I have a tab separated text file after executing some command in powershell i want to convert this tab separated file into csv now how can i do so?

like image 815
Abhishek_Mishra Avatar asked Jan 23 '12 10:01

Abhishek_Mishra


People also ask

How do I convert a text file to a CSV file in PowerShell?

You can use the Export-Csv cmdlet to convert objects to CSV strings. Export-CSV is similar to ConvertTo-CSV , except that it saves the CSV strings to a file. The ConvertTo-CSV cmdlet has parameters to specify a delimiter other than a comma or use the current culture as the delimiter.

How do I convert a TXT file to CSV?

Go to File > Save As. Click Browse. In the Save As dialog box, under Save as type box, choose the text file format for the worksheet; for example, click Text (Tab delimited) or CSV (Comma delimited).


1 Answers

A tab separated text file could be treated as a CSV file with a tab instead of comma as its delimiter. To convert:

import-csv tabdelimitedfile.txt -delimiter "`t" | export-csv csvfile.csv
like image 159
jon Z Avatar answered Sep 28 '22 05:09

jon Z