13

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?

5
  • Can you elaborate on how you end up with a tab-delimited file? It is likely you are making things more complicated than necessary. Commented Jan 23, 2012 at 10:45
  • Sorry for not telling detail. Actualy I am executing get-process command in a loop to get the detail about a process in a text file and updating it in some interval.Now when process stops my scripts also stops. Here I want that before stoping the script the text file should be read and the data should be shown in a csv file along with its headers..Becoz opening it in MSExcel wud give gud looking results.. Commented Jan 23, 2012 at 11:22
  • In your scenario it would be better to export your data directly to csv. Something like this: while ($true) {sleep 5; ps iexplore | select Handles, NPM, PM, WS, VM, CPU, Id, Name, @{N="SampleDateTime";E={(get-date)}} | export-csv -Append -NoTypeInformation process.csv} Commented Jan 23, 2012 at 12:02
  • IN this case i have a prob with appending data..dats y i dint tried dat..-Append will not work.. Commented Jan 23, 2012 at 12:15
  • It works on my machine. Please consider posting the sample code where append is not working as expected (as a separate question). Commented Jan 23, 2012 at 12:20

1 Answer 1

25

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
Sign up to request clarification or add additional context in comments.

2 Comments

Adding -NoType to the end of that line will get rid of the "#TYPE System.Management.Automation.PSCustomObject" line at the top of the output file.
This seems to add double quotes, is there a way to omit double quotes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.