Read text and copy to new text file

I have a text file with some data between line. like so:



How can I extract the data between the lines ans create a new Text file with the extracted data.

What kind of character is the horizontal line? Is it just dashes? Doesn’t look so from your sample text but it would be important to know. I would suggest using a simple where-object statement to select the data from lines that aren’t the horizontal line, or matching the actual data on the lines you’re trying to keep.

Get-Content c:\file.txt | Where-Object {$_ -match "X"} | Out-File c:\output.txt

That’s based on your sample content of course, considering it’s all X’s :slight_smile:

If you just want to ignore the lines, something like this would be what you need.

#requires -Version 1
Get-Content -Path C:\temp\file.txt |
Where-Object -FilterScript {
    $_ -notlike '--*'
} |
Out-File -FilePath C:\Temp\newfile.txt

The text file I have looks like:

Data: Data
Data: Data
Data: Data

Data: Data
Data: Data
Data: Data

How can I get just the first set of data and save it into a new text file and do the same for the second set and save the new text file

I have this code. which does the job but I need to loop through the text file.

Get-Content -Path 'C:\Test\FinancialStatements\Perez, Wilfredo 5-19-2015.txt' | 
    Select-String 'Transaction Type:'  -Context 0,15 | 
        Select-Object -First 1 | out-file 'C:\Test\FinancialStatements\OutPut.txt'


This is post # 4 by my count for the exact same question:

My last solution in parsed the files the way you asked with the example dataset you provided, so I’m unsure why you are creating yet another post of the exact same thing. If something is not working as expected, tell us what is not working so that we can work from the same requirements and see the current used solutions that were provided to you. Just starting the same question over and over with different requirements is just wasting everyone’s time. Provide all of the requirements, example data to be parsed, expected results in one post so that the community can assist you with your question(s).