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?

  • 1
    Can you use Powershell? – Ryan Ries Mar 28 '16 at 14:01
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.