{"id":6484,"date":"2018-08-30T19:31:31","date_gmt":"2018-08-30T15:31:31","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-colrm-command\/"},"modified":"2018-08-30T19:31:31","modified_gmt":"2018-08-30T15:31:31","slug":"linux-colrm-command-tutorial-for-beginners-with-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-colrm-command-tutorial-for-beginners-with-examples\/","title":{"rendered":"Linux colrm Command Tutorial for Beginners (with Examples)"},"content":{"rendered":"<p>If you primarily work on the Linux command line, text editing is likely one of the most frequent tasks that you may find yourself involved in. Whether it&#8217;s editing scripts, source code files, configuration files, or a regular text file, there are several text editing tools that help you in your work.<\/p>\n<p>One such tool is <strong>colrm<\/strong>, which we will be discussing here using some easy to understand examples. But before we start with that, it&#8217;s worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-colrm-command\">Linux colrm command<\/h2>\n<p>The colrm command in Linux lets you remove selected columns from a file. Following is its syntax:<\/p>\n<p class=\"command\">colrm [start [stop]]<\/p>\n<p>And here&#8217;s how the colrm man page describes what the tool does:<\/p>\n<pre readability=\"11\"> The colrm utility removes selected columns from the lines of a file.\u00a0 A<br\/>\u00a0\u00a0\u00a0\u00a0 column is defined as a single character in a line.\u00a0 Input is read from<br\/>\u00a0\u00a0\u00a0\u00a0 the standard input.\u00a0 Output is written to the standard output.<p>\u00a0\u00a0\u00a0\u00a0 If only the start column is specified, columns numbered less than the<br\/>\u00a0\u00a0\u00a0\u00a0 start column will be written.\u00a0 If both start and stop columns are speci?<br\/>\u00a0\u00a0\u00a0\u00a0 fied, columns numbered less than the start column or greater than the<br\/>\u00a0\u00a0\u00a0\u00a0 stop column will be written.\u00a0 Column numbering starts with one, not zero.<\/p><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the colrm command works.<\/p>\n<h2 id=\"q-how-to-use-colrm-command\">Q1. How to use colrm command?<\/h2>\n<p>As already mentioned, the colrm command lets you remove columns. So you just need to specify a numeric value, and column corresponding to that value as well as all the\u00a0subsequent columns will get axed in the output.<\/p>\n<p>For example, here&#8217;s a text file &#8216;file1.txt&#8217; that contains the following text:<\/p>\n<pre>abcdefgh<\/pre>\n<p>For colrm, each alphabet represents a column. So now, suppose the requirement is to delete column 6 and all susequent columns, then this can be done using:<\/p>\n<p class=\"command\">colrm 6 &lt; file1.txt<\/p>\n<p>Following is the output the above command will produce:<\/p>\n<p><a class=\"fancybox\" id=\"img-colrm-basic-usage\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/colrm-basic-usage.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-colrm-command-tutorial-for-beginners-with-examples.png\" alt=\"colrm command usage\" width=\"364\" height=\"37\" title=\"\"><\/a><\/p>\n<p>So you can see that columns 6, ,7 and 8 were axed.<\/p>\n<h2 id=\"q-how-to-remove-only-a-single-column\">Q2. How to remove only a single column?<\/h2>\n<p>In that case, you need to\u00a0specify both start and stop columns. Suppose the requirement is to delete only column number 6, then for that, you need to execute the colrm command in the following way:<\/p>\n<p class=\"command\">colrm 6 6 &lt; file1.txt<\/p>\n<p>Here&#8217;s the output this command produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-colrm-single-column\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/colrm-single-column.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-colrm-command-tutorial-for-beginners-with-examples-1.png\" alt=\"How to remove only a single column\" width=\"384\" height=\"37\" title=\"\"><\/a><\/p>\n<p>So you can see only the 6th column was deleted. Needless to say, you can delete a range of columns this way. For example:<\/p>\n<p class=\"command\">colrm 2 6 &lt; file1.txt<\/p>\n<p>This command will delete columns ranging from 2 to 6. It&#8217;s worth keeping in mind that the column numbering starts from 1, not zero.<\/p>\n<h2 id=\"q-how-colrm-handles-backspaces-and-tabs\">Q3. How colrm handles backspaces and tabs?<\/h2>\n<p>The tool&#8217;s man page explains this quite clearly. Here&#8217;s the relevant excerpt:<\/p>\n<pre> Tab characters increment the column count to the next multiple of eight.<br\/>\u00a0\u00a0\u00a0\u00a0 Backspace characters decrement the column count by one.<\/pre>\n<p>Also, keep in mind that colrm returns 0 on success, and &gt;0 if an error occurs.<\/p>\n<h2 id=\"q-how-to-make-colrm-accept-input-from-stdin\">Q4. How to make colrm accept input from stdin?<\/h2>\n<p>That&#8217;s very easy. You don&#8217;t have to do anything extra &#8211; just provide column number (or range) in input.<\/p>\n<p>Here&#8217;s an example:<\/p>\n<p><a class=\"fancybox\" id=\"img-colrm-stdin\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/colrm-stdin.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-colrm-command-tutorial-for-beginners-with-examples-2.png\" alt=\"How to make colrm accept input from stdin\" width=\"275\" height=\"75\" title=\"\"><\/a><\/p>\n<p>So the command waits for you to provide the input at run time, and then produces otutput after you press the enter key.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>As you&#8217;ll likely agree, the colrm command is a useful little utility when it comes to removing columns from a text file. Here, in this tutorial, we have discussed almost all of its features. Once you are done practicing these, you can learn more about the command by heading to its <a href=\"https:\/\/linux.die.net\/man\/1\/colrm\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a>.<\/p>\n<div class=\"authorbox\" readability=\"15\">\n<img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-colrm-command-tutorial-for-beginners-with-examples.jpg\" alt=\"Himanshu Arora\" title=\"\"> <\/p>\n<p><strong>About Himanshu Arora<\/strong><\/p>\n<p>Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu&#8217;s work has also been featured in some of world&#8217;s other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.<\/p>\n<\/div>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-colrm-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-colrm-command-tutorial-for-beginners-with-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-colrm-command%2F&amp;text=Linux+colrm+Command+Tutorial+for+Beginners+%28with+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-colrm-command-tutorial-for-beginners-with-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-colrm-command-tutorial-for-beginners-with-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-colrm-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-colrm-command-tutorial-for-beginners-with-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you primarily work on the Linux command line, text editing is likely one of the most frequent tasks that you may find yourself involved in. Whether it&#8217;s editing scripts, source code files, configuration files, or a regular text file, there are several text editing tools that help you in your work. One such tool &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-6484","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6484","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=6484"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6484\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=6484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=6484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=6484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}