{"id":2178,"date":"2017-07-27T01:00:56","date_gmt":"2017-07-27T05:00:56","guid":{"rendered":"http:\/\/www.rexfeng.com\/blog\/?p=2178"},"modified":"2017-07-27T01:00:56","modified_gmt":"2017-07-27T05:00:56","slug":"cli-cut-visual-option","status":"publish","type":"post","link":"https:\/\/www.rexfeng.com\/blog\/2017\/07\/cli-cut-visual-option\/","title":{"rendered":"CLI Cut Visual Option"},"content":{"rendered":"<p>Something I came across recently was command line text manipulation with a CSV. The way that the list option is passed in is cool.<\/p>\n<p>For demonstration purposed, we have a contrived text document &#8220;dummy.txt&#8221; that happens to be delimited by the % character. The contents inside the file are:<\/p>\n<pre>name%car%temp%color\r\njohn%honda%fair%blue\r\ntom%benz%fair%red\r\ned%bmw%cold%green<\/pre>\n<p>To get the first column of data, you can run<\/p>\n<pre>cut -d% -f1 dummy.txt<\/pre>\n<p>which gives you:<\/p>\n<pre>name\r\njohn\r\ntom\r\ned<\/pre>\n<p>If you wanted to save the output, the standard command line &#8220;&gt;&#8221; comes in handy.<\/p>\n<p>To get the columns up to (and including the) 2nd column, you can run<\/p>\n<pre class=\"p1\"><span class=\"s1\">cut -d% -f-2 dummy.txt<\/span><\/pre>\n<p>which gives you:<\/p>\n<pre>name%car\r\njohn%honda\r\ntom%benz\r\ned%bmw<\/pre>\n<p>To get the 2nd &amp; 3rd columns, inclusive, you can run<\/p>\n<pre>cut -d% -f2-3 dummy.txt<\/pre>\n<p>which gives you:<\/p>\n<pre>car%temp\r\nhonda%fair\r\nbenz%fair\r\nbmw%cold<\/pre>\n<p>To get the 3rd column onward to the last column, you can run<\/p>\n<pre class=\"p1\"><span class=\"s1\">cut -d% -f3- dummy.txt<\/span><\/pre>\n<p>which gives you:<\/p>\n<pre>temp%color\r\nfair%blue\r\nfair%red\r\ncold%green<\/pre>\n<p>The examples above are just for this demo, but I think the hyphen syntax in the list fields option is easy to learn and visually clear (for a CLI interface).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Something I came across recently was command line text manipulation with a CSV. The way that the list option is passed in is cool. For demonstration purposed, we have a contrived text document &#8220;dummy.txt&#8221; that happens to be delimited by the % character. The contents inside the file are: name%car%temp%color john%honda%fair%blue tom%benz%fair%red ed%bmw%cold%green To get [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1029],"tags":[1338,1343,1342,1341,1340,1339,1059],"class_list":["post-2178","post","type-post","status-publish","format-standard","hentry","category-programming","tag-cli","tag-columns","tag-csv","tag-cut","tag-fields","tag-list","tag-text"],"_links":{"self":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/2178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/comments?post=2178"}],"version-history":[{"count":1,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/2178\/revisions"}],"predecessor-version":[{"id":2179,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/posts\/2178\/revisions\/2179"}],"wp:attachment":[{"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/media?parent=2178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/categories?post=2178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rexfeng.com\/blog\/wp-json\/wp\/v2\/tags?post=2178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}