2

I have a lot of big text files. And I'm searching (within cmd.exe) for a list of values in them as following:

findstr /i /n /g:strings.txt 1\*.* >results.txt

where strings.txt is the file with all the values I'm looking for and 1 is a folder where all my text files are.

There is valuable information in preceding and next strings to the one that I can find with findstr. Could you please help me writing a script to have 3 lines in results.txt for each match?

Vasily
  • 21
  • 1

1 Answers1

1

Powershell. Specifically, the -Context parameter of the Select-String Cmdlet will give you the context surrounding the selected text.

PS C:\Users\ryan> gc .\temp.txt
1
2
3
4
5
6
7
8
9
10

PS C:\Users\ryan> gc .\temp.txt | Select-String '4' -Context 3

  1
  2
  3
> 4
  5
  6
  7
Ryan Ries
  • 55,011
  • 9
  • 138
  • 197