Search code examples
powershellfindstrpowershell-cmdlet

Ignore first line in FINDSTR search


I am searching an object-oriented Modelica library for a certain string using the following command in the Windows 7 PowerShell:

findstr /s /m /i "Searchstring.*" *.*

click for findstr documentation

The library consists of several folders containing text files with the actual code in them. To reduce the number of (unwanted) results, I have to ignore the first line of every text file.

Unfortunately, I cannot work out how to do this with the findstr command.


Solution

  • You can use Select-String instead of findstr

    To get all matches excluding the ones on the first line try something like this:

    Select-String -Path C:\dir\*.* -pattern "Searchstring*" | where {$_.LineNumber -gt 1}
    

    If you have to search subdirectories you can pair it with Get-Childitem:

    Get-Childitem C:\dir\*.* -recurse | Select-String -pattern "Searchstring*" | where {$_.LineNumber -gt 1}