View Single Post
Old 03-09-2008   #2 (permalink)
Marco Shaw [MVP]


 
 

Re: Possible to Read only Selected lines from multiple files intoanother file deleting source files when processed?

> I need to read only the data lines from each file into a single file
Quote:

> (data.out) and delete each .in file as it has been processed.
> I have gotten pretty close filtering by $_.Length -gt 6, but getting
> it into a single output file and then deleting the source file eludes
> me.
>
> Is this possible and if so how?
>
> Your help is greatly appreciated.
>
> Joe
Give this a try (change your paths accordingly):

get-childitem c:\demo2\tmp -recurse *.in|foreach-object{
select-string $_ -pattern "^dataline"|foreach-object{
add-content "c:\demo2\tmp\data.out" $_.tostring().split(":")[3]
}
remove-item $_.fullname -whatif
}

Welcome to PowerShell! ;-)

It may take a more than a few hours to get your head around things, but
its worth the ride!

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec