o4d5lw
Last Updated: June 24, 2016
·
113
· ryrych

Removing lines that match the pattern

vim

Suppose that you want to delete lines that contain passed phrase (you can use any valid regex). The file to be filtered out is list of failed rails specs. Like this:

example_id                                                                  | status  | run_time        |
--------------------------------------------------------------------------- | ------- | --------------- |
./spec/controllers/api/v1/accounts_controller_spec.rb[1:1:1:1]              | passed  | 0.20286 seconds |
./spec/controllers/api/v1/accounts_controller_spec.rb[1:1:2:1:1:1]          | passed  | 0.18228 seconds |
./spec/controllers/api/v1/attachments_controller_spec.rb[1:2:1:1:1]         | failed  | 1.37 seconds    |
./spec/controllers/api/v1/attachments_controller_spec.rb[1:2:1:2:1:1:1]     | failed  | 1.57 seconds    |

With:

g/passed/d

you’re left:

example_id                                                                  | status  | run_time        |
--------------------------------------------------------------------------- | ------- | --------------- |
./spec/controllers/api/v1/attachments_controller_spec.rb[1:2:1:1:1]         | failed  | 1.37 seconds    |
./spec/controllers/api/v1/attachments_controller_spec.rb[1:2:1:2:1:1:1]     | failed  | 1.57 seconds    |

You can also remove the lines that does not match the pattern with:

v/passed/d