{"id":220,"date":"2008-12-20T11:17:51","date_gmt":"2008-12-20T09:17:51","guid":{"rendered":"http:\/\/glandium.org\/blog\/?p=220"},"modified":"2010-01-27T08:52:26","modified_gmt":"2010-01-27T07:52:26","slug":"useless-use-of","status":"publish","type":"post","link":"https:\/\/glandium.org\/blog\/?p=220","title":{"rendered":"Useless use of &#8230;"},"content":{"rendered":"<p>(Inaugurating a new category which will be kind of my own <a href=\"http:\/\/thedailywtf.com\">dailty wtf<\/a>)<\/p>\n<p>A pretty well known matter is how some tools can be abused. Usually, it is <code>cat<\/code> or <code>grep<\/code>. Typical examples include the following two:<\/p>\n<blockquote><p><code>cat foo | grep bar<\/code><\/p><\/blockquote>\n<blockquote><p><code>grep bar foo | awk '{print $2}'<\/code><\/p><\/blockquote>\n<p>Obviously, the first one can be reduced to:<\/p>\n<blockquote><p><code>grep bar foo<\/code><\/p><\/blockquote>\n<p>and the second, to:<\/p>\n<blockquote><p><code>awk '\/bar\/ {print $2}' foo<\/code><\/p><\/blockquote>\n<p><code>awk<\/code> and <code>sed<\/code> are often part of the reason <code>grep<\/code> gets abused, because a lot of people don't know the latter form above or its <code>sed<\/code> equivalent. They don't know they could restrict the match on a specific column, too, which could be important in some cases.<\/p>\n<p>Anyways, a few months ago, I saw the most beautiful short piece of combined useless use of something I've ever seen, which also happens to be a pretty unusual type:<\/p>\n<blockquote><p><code>more $file | wc | awk '{print $1}'<\/code><\/p><\/blockquote>\n<p>Not only does it use <code>more<\/code> where even <code>cat<\/code>, while still being useless, would be a better choice, but it also manages to use <code>awk<\/code> where <code>wc<\/code> could take an option to achieve the same goal.<\/p>\n<p>Yes, the above can be simplified as:<\/p>\n<blockquote><p><code>wc -l &lt; $file<\/code><\/p><\/blockquote>\n<p>We never found who was responsible for this nicety.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Inaugurating a new category which will be kind of my own dailty wtf) A pretty well known matter is how some tools can be abused. Usually, it is cat or grep. Typical examples include the following two: cat foo | grep bar grep bar foo | awk &#8216;{print $2}&#8217; Obviously, the first one can be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[23],"class_list":["post-220","post","type-post","status-publish","format-standard","hentry","category-wtf","tag-en"],"_links":{"self":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220"}],"version-history":[{"count":3,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":659,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions\/659"}],"wp:attachment":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}