{"id":427,"date":"2009-08-20T09:17:36","date_gmt":"2009-08-20T14:17:36","guid":{"rendered":"http:\/\/www.gamescheat.ca\/?p=427"},"modified":"2019-09-04T19:57:40","modified_gmt":"2019-09-05T00:57:40","slug":"awk-the-swiss-army-knife-of-the-unix-toolkit","status":"publish","type":"post","link":"http:\/\/www.gamescheat.ca\/?p=427","title":{"rendered":"Awk the swiss army knife of the Unix toolkit."},"content":{"rendered":"<p>The awk command is very handy when you need to filter the contents of a file, a pipe,or keyboard.  It searches each line of input for patterns that you specify and when the pattern is matched, it performs an action.  You specify the action and patterns.<\/p>\n<div style=\"float: left;\"><div style=\"margin: 15px 15px 15px 15px\";><script type=\"text\/javascript\"><!--\ngoogle_ad_client = \"pub-3319935785736004\";\ngoogle_alternate_color = \"FFFFFF\";\ngoogle_ad_width = 120;\ngoogle_ad_height = 240;\ngoogle_ad_format = \"120x240_as\";\ngoogle_ad_type = \"text_image\";\ngoogle_ad_channel =\"\";\ngoogle_color_border = \"cccccc\";\ngoogle_color_link = \"cc0000\";\ngoogle_color_bg = \"ffffff\";\ngoogle_color_text = \"000000\";\ngoogle_color_url = \"008000\";\n\/\/--><\/script>\n<script type=\"text\/javascript\"\n  src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n<\/script><\/div><\/div><p>The action could be to count the number of times the word youtube appears in a file. There are many action options, it is really up to you to figure out how you can manipulate it.<\/p>\n<p>Here is an example, suppose you have the following text in the file myfile.<\/p>\n<p><em>What-is-the-word-to-remove-from-this-line.<\/em><\/p>\n<p><em>awk -F-remove \u2018\/-remove\/ {print $1}\u2019 myfile<\/em><\/p>\n<p><em>-F-remove<\/em>, is the field separator. In this case the separator is -remove, it separates the text before and after it into separate fields, logically speaking. <\/p>\n<p><em>-remove<\/em>, is the pattern to match, it has been defined as a field separator earlier with the -F option.  The pattern is enclosed within \/.<\/p>\n<p><em>print $1<\/em>, prints all text in the first column.  The column separator has been defined as the word -remove.  The input is from the file myfile.<\/p>\n<p>Here is the result of the awk command.<\/p>\n<p><em>what-is-the-word-to<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The awk command is very handy when you need to filter the contents of a file, a pipe,or keyboard. It searches each line of input for patterns that you specify and when the pattern is matched, it performs an action.&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/www.gamescheat.ca\/?p=427\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[55,35],"_links":{"self":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/427"}],"collection":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=427"}],"version-history":[{"count":3,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/427\/revisions"}],"predecessor-version":[{"id":430,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/427\/revisions\/430"}],"wp:attachment":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}