{"id":2565,"date":"2016-07-02T19:01:05","date_gmt":"2016-07-02T19:01:05","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=2565"},"modified":"2016-07-02T19:05:38","modified_gmt":"2016-07-02T19:05:38","slug":"2565","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=2565","title":{"rendered":"Removing data from between 2 points using SED"},"content":{"rendered":"<p>Let\u2019s take an plain text file, input.txt, that looks like this<\/p>\n<pre>PATTERN-1\r\nFirst line of unimportant text\r\nSecond line of unimportant text\r\nPATTERN-2<\/pre>\n<p>Some more texts (may\/ mayn&#8217;t be important!)<br \/>\nWe want to delete some of the lines from the file using the command line stream editor, sed.<\/p>\n<p>1. Use the following command to delete the lines lying between PATTERN-1 and PATTERN-2 , excluding the lines containing these patterns:<\/p>\n<pre>sed '\/PATTERN-1\/,\/PATTERN-2\/{\/\/!d}' input.txt<\/pre>\n<p>If you want to modify the file itself, instead of just the file stream, include the \u201c-i\u201d flag after sed.<\/p>\n<p>2. Use the following command to delete the lines lying between PATTERN-1 and PATTERN-2 , including the lines containing these patterns:<\/p>\n<pre>sed '\/PATTERN-1\/,\/PATTERN-2\/d' input.txt<\/pre>\n<p>3. To delete all the lines after PATTERN-2, use this<\/p>\n<pre>sed '\/PATTERN-1\/,$d' input.txt<\/pre>\n<p>4. To delete lines, say 2 through 4 (if you know the correct line numbers, of course!), use this<\/p>\n<pre>sed '2,4d' input.txt<\/pre>\n<p>A Great introduction can be found here<br \/>\n<a href=\"http:\/\/www.grymoire.com\/Unix\/Sed.html#uh-0\" target=\"_blank\">http:\/\/www.grymoire.com\/Unix\/Sed.html#uh-0<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s take an plain text file, input.txt, that looks like this PATTERN-1 First line of unimportant text Second line of unimportant text [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2565","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2565"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2565\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}