Solved

read a file and print

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

696 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