0

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.

Willi
  • 317
  • 2
  • 8
Jay_At_Play
  • 136
  • 10

2 Answers2

1

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}
Paul
  • 5,524
  • 1
  • 22
  • 39
  • I used the following code to search all files and subdirectories: `Get-ChildItem .\* -recurse | Select-String -pattern "Searchstring" | where {$_.LineNumber -gt 1}`. Your help is much appreciated, thanks! – Jay_At_Play Jan 28 '15 at 08:18
1

If you want to keep using findstr you could simply pipe the output into Select-Object:

findstr /s /m /i "Searchstring.*" *.* | select -Skip 1
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328