{"id":76,"date":"2011-12-20T15:40:28","date_gmt":"2011-12-20T15:40:28","guid":{"rendered":"http:\/\/tech.nes.aau.at\/?p=76"},"modified":"2011-12-20T15:44:32","modified_gmt":"2011-12-20T15:44:32","slug":"reverse-the-lines-of-a-file-in-bash","status":"publish","type":"post","link":"https:\/\/tech.nes.aau.at\/?p=76","title":{"rendered":"Reverse the lines of a file"},"content":{"rendered":"<p>Sometimes one needs things that cannot be done with a built-in function of Word or Libre Office Writer.<br \/>\nI needed to reverse the lines of a file. The IMHO most elegant solution to do this was:<\/p>\n<blockquote><p>cat -n myfile | sort -nr | cut -c 8- &gt; outfile.txt<\/p><\/blockquote>\n<p>Basically it is enumerating the lines of the file, sorting them in reverse order and then cutting away the numbers. Isn&#8217;t bash beautiful?<\/p>\n<p>Of course, Linux also has dedicated command to reverse the lines of a file, it is called <em>tac<\/em> (&#8216;cat&#8217; reversed).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes one needs things that cannot be done with a built-in function of Word or Libre Office Writer. I needed to reverse the lines of a file. The IMHO most elegant solution to do this was: cat -n myfile | &hellip; <a href=\"https:\/\/tech.nes.aau.at\/?p=76\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,1],"tags":[18,19,20],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-tools","category-uncategorized","tag-bash","tag-linux-text","tag-processing"],"_links":{"self":[{"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/posts\/76","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76"}],"version-history":[{"count":5,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.nes.aau.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}