{"id":1621,"date":"2013-05-07T11:14:39","date_gmt":"2013-05-07T11:14:39","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=1621"},"modified":"2013-05-07T11:14:39","modified_gmt":"2013-05-07T11:14:39","slug":"get-file-extension-in-bash","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=1621","title":{"rendered":"Get File Extension in BASH"},"content":{"rendered":"<p>The command basename is often used to extract the real file name without the file type specific file extension:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">basename thisfile.txt .txt<\/div><\/div>\n<p>thisfile<br \/>\nNow sometimes you need it the other way around, you might want to have the file extension. There are of course hundreds of ways to do so, but I found this one appealing since it also shows how the command awk works (which I should learn a bit better I think):<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">echo &quot;thisfile.txt&quot;|awk -F . '{print $NF}'<\/div><\/div>\n<p>txt<br \/>\nThe \u201c-F\u201d marks the delimiter, \u201c$NF\u201d means the last field generated. Seems to be a pretty straightforward tool.<\/p>\n<p>Also<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">echo &quot;thisfile.txt&quot; | rev | cut -c 1-3 | rev<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The command basename is often used to extract the real file name without the file type specific file extension: basename thisfile.txt .txt [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1621","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\/1621","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=1621"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1621\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}