.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
Post a Comment