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


 
 

Re: Searching large text files

mo is an alias for Measure-Object, oops!

Try this, it's pretty simple, ten lines, but the Count varies instead of
constantly being 10:

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

gc test.txt

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

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

# delete when done
ri test.txt

--
Kiron
My System SpecsSystem Spec