?
Solved

read a file and print

Posted on 2008-10-17
4
Medium Priority
?
203 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
[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
 

Author Comment

by:bt707
ID: 22741201
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 2000 total points
ID: 22741268
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
ID: 22741297
fyi... for the Excel stuff check this out

http://bsonposh.com/archives/357

Specifically the Cool Demo Code
0
 

Author Closing Comment

by:bt707
ID: 31507129
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses

770 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