Get the specific line RRS feed

  • Question

  • C:\Users\jassb> Get-Content 'C:\file.txt'|Select-String "Word" -context 0,8
    How to get only the eighth line after the searched word and not the lines between.
    Thursday, February 6, 2020 5:25 PM

All replies

  • YOU will have to code this in a loop and not use select-string.  Just use "match" then count 8 lines.


    Thursday, February 6, 2020 5:30 PM
  • $results = Select-String -Path 'c:\file.txt' "Word" -context 0,8

    Also if you process large file I would advise you to try new PowerShell 7.0. There Select-String has some new parameters and optimizations and works very fast in some scenarios.

    Сазонов Илья


    Friday, February 7, 2020 10:09 AM