{"id":2313,"date":"2019-02-25T23:08:29","date_gmt":"2019-02-25T23:08:29","guid":{"rendered":"http:\/\/www.incredigeek.com\/home\/?p=2313"},"modified":"2019-02-25T23:13:09","modified_gmt":"2019-02-25T23:13:09","slug":"vim-sed-search-and-replace-lines-that-do-not-contain-numbers","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/vim-sed-search-and-replace-lines-that-do-not-contain-numbers\/","title":{"rendered":"VIM\/SED Search and replace lines that do not contain numbers"},"content":{"rendered":"\n<p>Objective: Find all lines in a file that only contain alpha characters and delete or replace.<\/p>\n\n\n\n<p>Sample contents of file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> Z2j2NH23<br> VTQnPwSS<br> hFbxgvFt<br> VSVR8v3F<br> GPrP4zo<\/pre>\n\n\n\n<p>The following sed command works for our objective.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sed s\/[[:alpha:]]\\{8\\}\/ALPHAONLY\/g file.txt<\/pre>\n\n\n\n<p>The part in the [] tells sed to search for any alpha characters a-Z, the part in bold <strong>\\{8\\}<\/strong> tells it to search 8 spaces out (Change if needed) and ALPHAONLY is what alpha line will get substituted to.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sed s\/[[:alpha:]]<strong>\\{8\\}<\/strong>\/ALPHAONLY\/g<\/pre>\n\n\n<p><!--EndFragment--><br>\n<br>\n<\/p>\n\n\n<p>Returns<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Z2j2NH23<br>ALPHAONLY <br>ALPHAONLY <br>VSVR8v3F<br>GPrP4zo9<\/pre>\n\n\n\n<p>You can run the same basic syntax in VI<\/p>\n\n\n\n<p>Search and replace<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">:%s\/[[:alpha:]]\\{8\\}\/ALPHAONLY\/g <\/pre>\n\n\n\n<p>Or to delete the lines<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">:%d\/[[:alpha:]]\\{8\\}\/d<\/pre>\n\n\n\n<p>You can also change [[:alpha:]] for [[:digit:]] if you want to search for numbers instead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Objective: Find all lines in a file that only contain alpha characters and delete or replace. Sample contents of file. Z2j2NH23 VTQnPwSS hFbxgvFt VSVR8v3F GPrP4zo The following sed command works for our objective. sed s\/[[:alpha:]]\\{8\\}\/ALPHAONLY\/g file.txt The part in the &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/vim-sed-search-and-replace-lines-that-do-not-contain-numbers\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[586,587,5,6],"class_list":["post-2313","post","type-post","status-publish","format-standard","hentry","category-linux","tag-regex","tag-sed","tag-vi","tag-vim"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2313","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=2313"}],"version-history":[{"count":3,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2313\/revisions"}],"predecessor-version":[{"id":2318,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/2313\/revisions\/2318"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=2313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=2313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=2313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}