powershell - Regex replace contents of file and delete lines that don't match -
i have large log file want extract types of lines. have created working regex match these lines. how can use regex extract lines , nothing else? have tried
cat .\file | %{ if($_ -match "..."){ $_ -replace "...", '...' } else{ $_ -replace ".*", "" } } which works, lines not of interest still remain blank lines (meaning lines of interested spaced far apart).
the best way remove else clause altogether. if that, no object returned iteration of foreach-object block.
cat .\file | %{ if($_ -match "..."){ $_ -replace "...", '...' } }
Comments
Post a Comment