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

前端 未结 4 2046
臣服心动
臣服心动 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:13

    This might work for you:

    sed -n '/matchingpattern/p' file.txt
    

    /.../ is an address which may have actions attached in this case p.

提交回复
热议问题