Solved

read a file and print

Posted on 2008-10-17
4
197 Views
Last Modified: 2010-04-21
New to powershell, trying to figure out a simple output. I can do this with a small script or one liner in perl but not sure how to do this with using powershell

I have a lot of small text files with just one line in each one of them such as
Sminth1 20081010
JohnD2 2008109
Mary3 2008108
Bill4 20081015

I can read them with Get-Content, what I'm wanting to do is to read each of the lines in all the ..txt files and then put all lines into another file but separate the name and date with a tab, so just doing a Get-Content on all of the ..txt files and piping the output to one file works but does not tab separate the name and date.

How can I read the name and date in each file then output that to a tab separated list.

Thanks,
0
Comment
Question by:bt707
  • 2
  • 2
4 Comments
 

Author Comment

by:bt707
Comment Utility
I'm wanting to send the output to a tab separated list so I can put it in excel, so instead of just piping it to a .xls file was wondering if powershell had was of doing this as well. That was I do not pipe it to a .xls file then have to resave it as a regular excel file.
0
 
LVL 18

Accepted Solution

by:
BSonPosh earned 500 total points
Comment Utility
Here is the cmd

dir *.txt | get-content | %{"{0}`t{1}" -f $_.Split()[0],$_.Split()[1]} | out-file newfile.txt -enc ASCII


For future... here is the correct zone:http://www.experts-exchange.com/Programming/Languages/Scripting/MSH-Monad/
0
 
LVL 18

Expert Comment

by:BSonPosh
Comment Utility
fyi... for the Excel stuff check this out

http://bsonposh.com/archives/357

Specifically the Cool Demo Code
0
 

Author Closing Comment

by:bt707
Comment Utility
Worked Great.

Thanks for the help link to correct zone, I was looking for a powershell zone but did not see it.

Thanks again!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now