Author Posts

March 7, 2018 at 6:55 pm

I am working with very large text files, consisting of very log lines (> 1000 characters per line). Using select-string to find a 10-character string in these files takes a couple of minutes. I am trying to find ways to optimize the search.Is there a way that I could restrict the search to certain characters of each line in the text file. For example, I might know that the string I am searching for is in position 350 to 352. Thanks for any assistance.

March 7, 2018 at 9:31 pm

Working with large text files means, do not use Get-Content.

Why Get-Content Ain't Yer Friend
'powershell.org/2013/10/21/why-get-content-aint-yer-friend'

Use the .Net file libraries.

[System.IO.File]::ReadLines

How are you using Select-String?
-Pattern
-SimpleMatch
-AllMatches

Have you looked at the speed difference between Select-String and plain RegEx match?

March 8, 2018 at 3:04 pm

I'm not sure if this is faster but:

get-content text | foreach { $_.substring(349,361) } | select-string whatever10

Have you tried get-content's -readcount parameter?