Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert Tab delimited txt file to .csv in powershell

Posted on 2011-03-01
4
Medium Priority
?
4,808 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
  • 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 2000 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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

876 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