Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting an arbitrary amount of info from a txt file

Status
Not open for further replies.

daman7899

Programmer
Jul 16, 2012
1
US
Hello,

I have data in a txt file that looks like this:

80 E6 .. .. .. .. (Where the .. .. .. ..'s represent more byte data)
80 E8 .. .. .. ..
80 E8 .. .. .. ..
80 E6 .. .. .. ..
80 E6 .. .. .. ..
etc..

So I want to extract all data from the start value "80 E6" to the last end value of "80 E8". which would look like this:

80 E6 .. .. .. ..
80 E8 .. .. .. ..
80 E8 .. .. .. ..

No duplicates if 80 E6 is followed by another 80 E6.

When i do this:

Function Extractor{
$firstTag = '^80 E6.*$'

$secondTag = '^80 E6.*$'

$t= foreach ($line in (Get-Content C:\Users\tempFile.txt )) {


if ($line -match $firstTag) {

do {

$foreach.current


$foreach.MoveNext() > $null

}

until ($foreach.current -match $secondTag)

$foreach.current
}

}
$t | Out-file "C:\Users\tempFile.txt"
}
Extractor

Nothing happens and I dont get a return for anything execpt an empty out-file.

So is there a way so that I can only extract just those patterns of 80 E6 followed by an arbitrary number of 80 E8's? And I do not want the report to contain and 80 E6's back to back. Only 80 E6's followed by 80 E8's.



Thanks in advance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top