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
Solved

read a file and print

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

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

861 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