{"id":11463,"date":"2019-03-14T08:14:51","date_gmt":"2019-03-14T08:14:51","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11463"},"modified":"2019-03-14T08:14:51","modified_gmt":"2019-03-14T08:14:51","slug":"display-command-output-or-file-contents-in-column-format","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/display-command-output-or-file-contents-in-column-format\/","title":{"rendered":"Display Command Output or File Contents in Column Format"},"content":{"rendered":"<p>Are you fed up of viewing congested command output or file content on the terminal. This short article will demonstrate how to display command output or a file content in a much clear \u201c<strong>columnated<\/strong>\u201d format.<\/p>\n<p>We can use the\u00a0<strong>column<\/strong>\u00a0utility to transform standard input or a file content into tabular form of multiple columns, for a much clear output.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/linux-file-operations-commands\/\" target=\"_blank\" rel=\"noopener\">12 Useful Commands For Filtering Text for Effective File Operations in Linux<\/a><\/p>\n<p>To understand more clearly, we have created a following file \u201c<strong>tecmint-authors.txt<\/strong>\u201d which contains a list of top 10 authors names, number of articles written and number of comments they received on the article till now.<\/p>\n<p>To demonstrate this, run the\u00a0<a href=\"https:\/\/www.tecmint.com\/13-basic-cat-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cat command<\/a>\u00a0below to view the\u00a0<strong>tecmint-authors.txt<\/strong>\u00a0file.<\/p>\n<pre>$ cat tecmint-authors.txt\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>pos|author|articles|comments\r\n1|ravisaive|431|9785\r\n2|aaronkili|369|7894\r\n3|avishek|194|2349\r\n4|cezarmatei|172|3256\r\n5|gacanepa|165|2378\r\n6|marintodorov|44|144\r\n7|babin lonston|40|457\r\n8|hannyhelal|30|367\r\n9|gunjit kher|20|156\r\n10|jesseafolabi|12|89\r\n<\/pre>\n<p>Using the\u00a0<strong>column command<\/strong>, we can display a much clear output as follows, where the\u00a0<code>-t<\/code>\u00a0helps to determine the number of columns the input contains and creates a table and the\u00a0<code>-s<\/code>\u00a0specifies a delimiter character.<\/p>\n<pre>$ cat tecmint-authors.txt  | column -t -s \"|\"\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>pos  author         articles  comments\r\n1    ravisaive      431       9785\r\n2    aaronkili      369       7894\r\n3    avishek        194       2349\r\n4    cezarmatei     172       3256\r\n5    gacanepa       165       2378\r\n6    marintodorov   44        144\r\n7    babin lonston  40        457\r\n8    hannyhelal     30        367\r\n9    gunjit kher    20        156\r\n10   jesseafolabi   12        89\r\n<\/pre>\n<p>By default,\u00a0<strong>rows<\/strong>\u00a0are filled before columns, to fill columns before filling rows use the\u00a0<code>-x<\/code>\u00a0switch and to instruct column command consider empty lines (which are ignored by default), include the\u00a0<code>-e<\/code>\u00a0flag.<\/p>\n<p>Here is another practical example, run the two commands below and see difference to further understand the magic column can do<\/p>\n<pre>$ mount\r\n$ mount | column -t\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>sysfs        on  \/sys                             type  sysfs            (rw,nosuid,nodev,noexec,relatime)\r\nproc         on  \/proc                            type  proc             (rw,nosuid,nodev,noexec,relatime)\r\nudev         on  \/dev                             type  devtmpfs         (rw,nosuid,relatime,size=4013172k,nr_inodes=1003293,mode=755)\r\ndevpts       on  \/dev\/pts                         type  devpts           (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)\r\ntmpfs        on  \/run                             type  tmpfs            (rw,nosuid,noexec,relatime,size=806904k,mode=755)\r\n\/dev\/sda10   on  \/                                type  ext4             (rw,relatime,errors=remount-ro,data=ordered)\r\nsecurityfs   on  \/sys\/kernel\/security             type  securityfs       (rw,nosuid,nodev,noexec,relatime)\r\ntmpfs        on  \/dev\/shm                         type  tmpfs            (rw,nosuid,nodev)\r\ntmpfs        on  \/run\/lock                        type  tmpfs            (rw,nosuid,nodev,noexec,relatime,size=5120k)\r\ntmpfs        on  \/sys\/fs\/cgroup                   type  tmpfs            (rw,mode=755)\r\ncgroup       on  \/sys\/fs\/cgroup\/systemd           type  cgroup           (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=\/\r\n....\r\n<\/pre>\n<p>To save the nicely formatted output in a file, use the output redirection as shown.<\/p>\n<pre>$ mount | column -t &gt;mount.out\r\n<\/pre>\n<p>For more information, see the columns man page:<\/p>\n<pre>$ man column \r\n<\/pre>\n<p>You might also like to read these following related articles.<\/p>\n<ol>\n<li><a href=\"https:\/\/www.tecmint.com\/use-linux-awk-command-to-filter-text-string-in-files\/\" target=\"_blank\" rel=\"noopener\">How to Use Awk and Regular Expressions to Filter Text or String in Files<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/find-and-sort-files-modification-date-and-time-in-linux\/\" target=\"_blank\" rel=\"noopener\">How to Find and Sort Files Based on Modification Date and Time in Linux<\/a><\/li>\n<li><a href=\"https:\/\/www.tecmint.com\/linux-grep-commands-character-classes-bracket-expressions\/\" target=\"_blank\" rel=\"noopener\">11 Advanced Linux \u2018Grep\u2019 Commands on Character Classes and Bracket Expressions<\/a><\/li>\n<\/ol>\n<p>If you have any question, use the comment form below to write to us. You can as well share with us any useful command line tips and tricks in Linux.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/display-command-output-or-file-contents-in-column-format\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you fed up of viewing congested command output or file content on the terminal. This short article will demonstrate how to display command output or a file content in a much clear \u201ccolumnated\u201d format. We can use the\u00a0column\u00a0utility to transform standard input or a file content into tabular form of multiple columns, for a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/display-command-output-or-file-contents-in-column-format\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Display Command Output or File Contents in Column Format&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11463","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11463"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11463\/revisions"}],"predecessor-version":[{"id":11464,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11463\/revisions\/11464"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}