.net - Powershell io.streamreader "-context" equivalent command -


i using below code in powershell collect relevant data large txt file.

$sr = new-object system.io.streamreader(get-item c:\test.txt)  while (($line = $sr.readline()) -ne $null) {     if ($line -match "data") { $line }  }  $sr.dispose() 

this works useful if there equivalent powershell's select-string -context 1,0 able line above matched line.

can assist?

if need 1 previous line, following suffice:

$sr = new-object system.io.streamreader(get-item c:\test.txt)  while (($line = $sr.readline()) -ne $null) {     if ($line -match "data") { $prev_line, $line }     $prev_line = $line }  $sr.dispose() 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -