restrict select-string to certain columns of a text file

This topic contains 2 replies, has 3 voices, and was last updated by  js 2 months, 2 weeks ago.

  • Author
  • #95361

    Willem van der Eijk

    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.

  • #95398


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

    Why Get-Content Ain't Yer Friend

    Use the .Net file libraries.


    How are you using Select-String?

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

  • #95430


    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?

You must be logged in to reply to this topic.