View Single Post
Old 06-15-2007   #9 (permalink)
Kiron


 
 

Re: Searching large text files

Now try filtering each object with an If statement inside a Foreach-Object
scriptblock. Count is constantly 10 as expected.
Where-Object and Get-Content's -ReadCount <-gt 1> don't get along:

@'
a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
'@ > test.txt

gc test.txt

(gc test.txt -read 1 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 2 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 3 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 4 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 5 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 6 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 7 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 8 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 9 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count
(gc test.txt -read 10 | % {if ($_ -like '*a*') {$_}} | Measure-Object).count

(gc test.txt -read 1 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 2 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 3 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 4 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 5 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 6 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 7 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 8 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 9 | % {if ($_ -match 'a') {$_}} | Measure-Object).count
(gc test.txt -read 10 | % {if ($_ -match 'a') {$_}} | Measure-Object).count

# delete when done
ri test.txt

--
Kiron

My System SpecsSystem Spec