![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Possible to Read only Selected lines from multiple files into anotherfile deleting source files when processed? My experience with powershell is measured in hours, but I've got to say I'm STOKED at what I've seen so far! I've used my so far limited skills in an attempt to do the following without success: I have a folder containing zero to many files named like *.in their contents are roughly the following format: Header dataline xxxxxxxxxxxxxxxxxxxxxxxxxxUseMexxxxxxxxxxxxxxxxxxxxxxxxxxxxx dataline xxxxxxxxxxxxxxxxxxxxxxxxxxUseMexxxxxxxxxxxxxxxxxxxxxxxxxxxxx EOF I need to read only the data lines from each file into a single file (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 |
My System Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | Re: Possible to Read only Selected lines from multiple files intoanother file deleting source files when processed? On Mar 9, 6:43*pm, "Marco Shaw [MVP]" <marco.shaw@_NO_SPAM_gmail.com> wrote: Quote: Quote: > > I need to read only the data lines from each file into a single file > > (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. Quote: > > Is this possible and if so how? Quote: > > Your help is greatly appreciated. Quote: > > 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 PowerShellhttp://www.microsoft.com/mvp > > PowerGadgets MVPhttp://www.powergadgets.com/mvp > > Blog:http://marcoshaw.blogspot.com Thanks for your response - intriguing! I couldn't get it to actually put the detail line into the file data.out until I removed '.split(":")[3]' - what does that do? Thanks again for your help, Joe |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Possible to Read only Selected lines from multiple files intoanother file deleting source files when processed? Quote: > Thanks for your response - intriguing! > I couldn't get it to actually put the detail line into the file > data.out until I removed '.split(":")[3]' - what does that do? something different for me. ..split is a method where the string passed is split-up into elements by the character passed to it (":" in this case). "[3]" simply means that once the string is split, get me the 4th element (4th because PowerShell counts starting at 0 in this case). Marco |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Delete all .processed files | VB Script | |||
| Remove lines from multiple text files | PowerShell | |||
| Read multiple files with script | VB Script | |||
| Retrieving selected lines from all text files in a directory | PowerShell | |||
| Can One Folder display Files from multiple source folders? | Vista file management | |||