Solved

Convert Tab delimited txt file to .csv in powershell

Posted on 2011-03-01
4
4,404 Views
Last Modified: 2012-05-11
I need to convert a text file to .csv using powershell. The column headers should be

Name     Path        Full      Incr

I would like it sorted by first column name.


Please provide exact code
0
Comment
Question by:LouisSanchez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 35013332
Are the headers in the text file? if so you can try this

$in = import-csv c:\import.txt -Delimiter `t
$in | Sort Name | export-csv c:\out.csv
0
 

Author Comment

by:LouisSanchez
ID: 35013507
Sorry headers aren't in txt file
0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 35013613
There are probably better ways to do this but see if this works for you


$test = gc c:\temp\2.txt
$u = @()
$u += "Name `t Path `t Full `t Incr"
$test | %{$u += $_}
ConvertFrom-Csv -inputobject $u -delimiter `t | export-csv c:\temp\testout.csv -notypeinformation

Open in new window

0
 

Author Closing Comment

by:LouisSanchez
ID: 35018781
Worked awesome. Thanks
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question