Remove all lines except matching pattern line best practice (sed)

前端 未结 4 2015
臣服心动
臣服心动 2021-01-03 21:43

I want to remove all lines except the line(s) containing matching pattern.

This is how I did it:

sed -n \'s/matchingpattern/matchingpattern/p\' file.         


        
4条回答
  •  孤城傲影
    2021-01-03 22:04

    Instead of using sed, which is complicated, use grep.

    grep matching_pattern file
    

    This should give you the desired result.

提交回复
热议问题