Author Posts

May 29, 2015 at 12:28 pm

I have a text file with some data between line. like so:
_________________________________________________________
XXXXXXXXXXXXX
XXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
_______________________________________________________________
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
_________________________________________________________________

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

May 29, 2015 at 7:10 pm

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 🙂

May 29, 2015 at 10:06 pm

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

June 1, 2015 at 7:43 am

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

June 1, 2015 at 7:53 am

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'

June 1, 2015 at 8:29 am

@Fred

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

Read text file and find match

Powershell Regex and Excel

Select-String Regex

My last solution in https://powershell.org/forums/topic/read-text-file-and-find-match/ 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).