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

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -