Truncate long strings in columns and use custom header names

column -s: -t -n . -N USERNAME,PASS,UID,GID,NAME,HOMEDIR,SHELL -T NAME /etc/passwd|sed "1,2 i $(printf %80s|tr ' ' '=')"
Using the --table-truncate ( -T ) option, you can specify the columns you will allow to be truncated. This helps when you have some columns that are unusually long, or a small terminal window. In this example we will print out the /etc/passwd file in columns. We are using a colon as our separator ( -s: ), defining that we want table output ( -t ), defining the column names ( -N ) and allowing the column NAME to be truncated ( -T ).
Sample Output
================================================================================
USERNAME    PASS  UID    GID    NAME    HOMEDIR                   SHELL
================================================================================
root        x     0      0      root    /root                     /bin/bash
bin         x     1      1      bin     /bin                      /bin/false
daemon      x     2      2      daemon  /sbin                     /bin/false
adm         x     3      4      adm     /var/adm                  /bin/false
lp          x     4      7      lp      /var/spool/lpd            /bin/false
sync        x     5      0      sync    /sbin                     /bin/sync
shutdown    x     6      0      shutdo  /sbin                     /sbin/shutdown
halt        x     7      0      halt    /sbin                     /sbin/halt
news        x     9      13     news    /var/spool/news           /bin/false
uucp        x     10     14     uucp    /var/spool/uucp           /bin/false

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: