Windows: findstr – how to print 3 lines before and after matched lines?

If you are open for a command in Powershell (since you seem to on Win7), ..

PS C:\Users\user> Get-Content data.txt
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve

PS C:\Users\user> Get-Content data.txt | Select-String -Pattern four -Context 2,4

  two
  three
> four
  five
  six
  seven
  eight

The Get-Content command gets the the file specified. The Select-String command takes a pattern that you want to find. The Context command let’s you specify how many lines (before/after) that you want to be shown (around the line that it matched).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)