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

java - Ebean enhancement ignores a model -

javascript - Reference error while trying to encapsulate an animation function -

SQL php on different pages to Insert (mysqli) -