{"id":3721,"date":"2023-12-28T16:21:47","date_gmt":"2023-12-28T21:21:47","guid":{"rendered":"https:\/\/osric.com\/chris\/accidental-developer\/?p=3721"},"modified":"2023-12-28T16:21:47","modified_gmt":"2023-12-28T21:21:47","slug":"3-ways-to-remove-blank-lines-from-a-file","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2023\/12\/3-ways-to-remove-blank-lines-from-a-file\/","title":{"rendered":"3 ways to remove blank lines from a file"},"content":{"rendered":"<p>There are certainly more than 3 ways to do this. Typically I&#8217;ve always used <code>sed<\/code> to do this, but here&#8217;s my method using <code>sed<\/code> and two other methods using <code>tr<\/code> and <code>awk<\/code>:<\/p>\n<p><strong>sed:<\/strong><\/p>\n<pre><code>sed '\/^$\/d' file_with_blank_lines<\/code><\/pre>\n<p><strong>tr:<\/strong><\/p>\n<pre><code>tr -s '\\n' &lt;file_with_blank_lines<\/code><\/pre>\n<p><strong>awk:<\/strong><\/p>\n<pre><code>awk '{ if ($0) print $0 }' file_with_blank_lines<\/code><\/pre>\n<p>If you have other favorite ways, leave a note in the comments!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>3 short command-line methods for removing blank lines from text files<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[232],"tags":[406,293],"class_list":["post-3721","post","type-post","status-publish","format-standard","hentry","category-tips-tricks","tag-awk","tag-sed"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3721","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=3721"}],"version-history":[{"count":3,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3721\/revisions"}],"predecessor-version":[{"id":3725,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/3721\/revisions\/3725"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=3721"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=3721"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=3721"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}