how to remove lines from file that don't match regex?

前端 未结 5 1155
傲寒
傲寒 2021-01-22 04:05

I have a big file that looks like this:

7f0c41d6-f9c6-47aa-a034-d40bc629c973.csv
159890
159891
24faaed6-62ee-4175-8430-5d73b09911c8.csv
159907
5bad221f-25ef-44fa         


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 04:43

    If you are familiar with the vim text editor (vim or vi is typically installed on many linux boxes), use the following vim Ex mode command to remove lines that don't match a particular pattern:

    :v//d
    

    For example, if I wanted to delete all lines that didn't contain "column" I would run:

    :v/"column"/d
    

    Hope this helps.

提交回复
热议问题