{"id":3325,"date":"2020-05-04T17:17:18","date_gmt":"2020-05-04T22:17:18","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=3325"},"modified":"2020-05-04T17:17:32","modified_gmt":"2020-05-04T22:17:32","slug":"vim-delete-all-lines-not-matching-pattern","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/vim-delete-all-lines-not-matching-pattern\/","title":{"rendered":"VIM delete all lines not matching pattern"},"content":{"rendered":"\n<p>In Vi you can use the following command to search for a pattern and delete all those lines<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">:%g\/pattern-to-search-for\/d<\/pre>\n\n\n\n<p>To inverse the operation and delete all lines not matching the pattern, change g to v<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">:%v\/pattern-to-search-for\/d<\/pre>\n\n\n\n<figure class=\"wp-block-gallery columns-2 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"361\" height=\"266\" src=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-04-at-5.11.50-PM.png\" alt=\"\" data-id=\"3333\" data-full-url=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-04-at-5.11.50-PM.png\" data-link=\"https:\/\/www.incredigeek.com\/home\/?attachment_id=3333\" class=\"wp-image-3333\" srcset=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-04-at-5.11.50-PM.png 361w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-04-at-5.11.50-PM-300x221.png 300w\" sizes=\"auto, (max-width: 361px) 100vw, 361px\" \/><figcaption class=\"blocks-gallery-item__caption\">Search and delete lines matching pattern<\/figcaption><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img loading=\"lazy\" decoding=\"async\" width=\"361\" height=\"266\" src=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-04-at-5.10.35-PM.png\" alt=\"\" data-id=\"3332\" data-full-url=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-04-at-5.10.35-PM.png\" data-link=\"https:\/\/www.incredigeek.com\/home\/?attachment_id=3332\" class=\"wp-image-3332\" srcset=\"https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-04-at-5.10.35-PM.png 361w, https:\/\/www.incredigeek.com\/home\/wp-content\/uploads\/2020\/05\/Screen-Shot-2020-05-04-at-5.10.35-PM-300x221.png 300w\" sizes=\"auto, (max-width: 361px) 100vw, 361px\" \/><figcaption class=\"blocks-gallery-item__caption\">Search and delete lines not matching pattern<\/figcaption><\/figure><\/li><\/ul><\/figure>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\"><div class=\"wp-block-group__inner-container\"><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In Vi you can use the following command to search for a pattern and delete all those lines :%g\/pattern-to-search-for\/d To inverse the operation and delete all lines not matching the pattern, change g to v :%v\/pattern-to-search-for\/d<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,1015],"tags":[1011,1013,1012,1014,5,6],"class_list":["post-3325","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-vim","tag-editor","tag-pattern","tag-search","tag-search-and-delete","tag-vi","tag-vim"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=3325"}],"version-history":[{"count":1,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3325\/revisions"}],"predecessor-version":[{"id":3334,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/3325\/revisions\/3334"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=3325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=3325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=3325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}