|
Re: Parsing Text File and returning variables Thanks for your help guys, here is pretty much what I've come up and
it seems to work perfectly so far. Basically it just converts the file
to one big string, splits it into one word per line and because the
file is always the same layout its easy to do the offsets manually
(the files are infact much bigger, but this is just the basic format).
I look for a single distinct search string per line (from the
original) but if thats not possible i just use some nested switch
statements to get the desired result (for example I have readings for
"zone 1", "zone 2", etc).
################################################
dir awaiting\*.txt | foreach{
$words = gc $_
$words = [string]::join(" ", $words)
$words = $words.split(" ",[stringsplitoptions]::RemoveEmptyEntries)
$count = $words.count
$index = 0
while ($index -ne $count)
{
switch ($words[$index])
{
code{$ProdCode= $words[$index+1];$Prodcode}
Time={$Time= $words[$index+1];$Time}
order{$CO= $words[$index+2];$CO}
Date={$Date= $words[$index+1];$Date}
Zone{switch($words[$index+1])
{
1{$TempZone1=$words[$index+3] ;$TempZone1}
2{$TempZone2=$words[$index+3] ;$TempZone2}
3{$TempZone3=$words[$index+3] ;$TempZone3}
4{$TempZone4=$words[$index+3] ;$TempZone4}
}
}
$index++
}
} |