Remove everything except regex match in Vim

前端 未结 4 556
深忆病人
深忆病人 2020-11-29 04:22

My specific case is a text document that contains lots of text and IPv4 addresses. I want to remove everything except for the IP addresses.

I can use :vglobal<

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 04:58

    In short, I'm looking for a way to do this without leaving vim

    Easy enough:

    :1,$! grep --extended-regexp --only-matching --regexp="([0-9]{1,3}\.){3}[0-9]{1,3}"
    

    (though I actually voted up icecrime's substitution answer)

提交回复
热议问题