Sunday, November 2, 2014

Command of the day: column

Often I come across a new command which I think Wow! I always wanted to know how to do that.

I decided that I will blog about them and that way I will have a record for next time when I forget how to do it.

So my first command of the day I is one I saw on a Red Hat post. It can show the contents of a file tabulated into easy to read columns.

Example:
cat /etc/passwd | column -s : -t


Now you are probably aware of the <tab> character, often entered as \t or in bash as $'\t'. It will advance the cursor to the next tab stop which is traditionally every 8 characters. Well what if you have a tab delimited file but some data is longer than 8 characters and some it less. Well when you look at it, the output will be all over the place.

Using column you can get all your tab columns to line up like this:
cat data | column -s $'\t' -t
Note: for this to work correctly you must have a value in every column (perhaps a bug?)

6 comments:

  1. I think this is an informative post and it is very useful and knowledgeable. I really enjoyed reading this post gmail login

    ReplyDelete
  2. Nice, Great website Thanks For Sharing
    Angelina

    ReplyDelete
  3. I wanted to thank you for this excellent read!! I definitely loved every little bit of it
    - slope game -

    ReplyDelete
  4. Thanks for sharing happy wheels these tips, these tips are very helpful and useful.

    ReplyDelete
  5. Good article and knowledge for me! I found a lot of information here! This article is really good for all newbie here. Thank you for sharing with us!
    asianfanfics

    ReplyDelete
  6. This is extremely helpful info!! Very good work. Everything is very interesting to learn and easy to understood. Thank you for giving information.

    run 3

    ReplyDelete