Solved

read a file and print

Posted on 2008-10-17
4
199 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
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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
USB backup batch file help needed. 9 97
Windows Batch File - Combing output in a single line 3 65
Need help to rewrite script 3 80
excel file 5 72
Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

777 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