Facebook Twitter Instagram
    WiredRevolution.com
    • Home
    • About
    • Contact Us
    • Essential Linux Commands
    • Sitemap
    Facebook Twitter Instagram
    WiredRevolution.com
    commands

    Format output with the column utility

    RyanBy RyanJanuary 29, 2011Updated:January 29, 20111 Comment2 Mins Read
    Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email

    The column utility is helpful for taking raw data and formatting it in a way that is easier for humans to comprehend. It can take a single column of data and format it into many equally spaced columns. Alternatively it can format multiple rows of data into tables.

    In our first example we have a numfile which contains 20 numbers, one on each line, which we output with cat.

    $ cat numfile1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    The output is long and you can quickly see with a larger example that the numbers would scroll off the screen. When we pipe this same output to the column command the output is broken into columns and is evenly distributed across the screen.

    $ cat numfile | column1       3       5       7        9      11      13      15      17      19
    2       4       6       8       10      12      14      16      18      20

    The ‘-t’ option determines the number of columns the input contains and creates a table. This is helpful when you have data where the fields have various lengths. A good example to demonstrate this is the white space delimited output from /etc/mtab.

    $ cat /etc/mtabproc /proc proc rw,noexec,nosuid,nodev 0 0
    none /sys sysfs rw,noexec,nosuid,nodev 0 0
    fusectl /sys/fs/fuse/connections fusectl rw 0 0
    none /sys/kernel/debug debugfs rw 0 0
    none /sys/kernel/security securityfs rw 0 0
    none /dev devtmpfs rw,mode=0755 0 0
    none /dev/pts devpts rw,noexec,nosuid,gid=5,mode=0620 0 0
    none /dev/shm tmpfs rw,nosuid,nodev 0 0
    none /var/run tmpfs rw,nosuid,mode=0755 0 0
    none /var/lock tmpfs rw,noexec,nosuid,nodev 0 0
    none /var/lib/ureadahead/debugfs debugfs rw,relatime 0 0
    binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,noexec,nosuid,nodev 0 0

    With the same output piped to column. the resulting table is much more readable.

    $ cat /etc/mtab | column -tproc              /proc                        proc                   rw,noexec,nosuid,nodev            0  0
    none              /sys                         sysfs                  rw,noexec,nosuid,nodev            0  0
    fusectl           /sys/fs/fuse/connections     fusectl                rw                                0  0
    none              /sys/kernel/debug            debugfs                rw                                0  0
    none              /sys/kernel/security         securityfs             rw                                0  0
    none              /dev                         devtmpfs               rw,mode=0755                      0  0
    none              /dev/pts                     devpts                 rw,noexec,nosuid,gid=5,mode=0620  0  0
    none              /dev/shm                     tmpfs                  rw,nosuid,nodev                   0  0
    none              /var/run                     tmpfs                  rw,nosuid,mode=0755               0  0
    none              /var/lock                    tmpfs                  rw,noexec,nosuid,nodev            0  0
    none              /var/lib/ureadahead/debugfs  debugfs                rw,relatime                       0  0
    binfmt_misc       /proc/sys/fs/binfmt_misc     binfmt_misc            rw,noexec,nosuid,nodev            0  0

    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
    Previous ArticleVirtualBox 4.0 upgrade and the Oracle VM VirtualBox Extension Pack
    Next Article Echo text without a trailing newline

    Related Posts

    YouTube Begins Transcoding All Video to WEBM

    Fix Alt Tab task switching in GNOME Shell

    Get a Listing of Directories in a Subdirectory

    Most Commented
    March 12, 2009

    Fix blue tinted video in Ubuntu

    September 10, 2010

    Setup SSH access between VirtualBox Host and Guest VMs

    March 8, 2011

    Install GNOME Shell in Ubuntu 10.10 Maverick

    April 4, 2009

    Setup the PS3 Bluetooth Controller on Ubuntu

    October 22, 2008

    How to correctly use LD_LIBRARY_PATH

    Recent Comments
    • Execute command on linux virtual machine (or server) from windows commandline on Setup SSH access between VirtualBox Host and Guest VMs
    • Solved: How to SSH to a VirtualBox guest externally through a host? - Daily Developer Blog on Setup SSH access between VirtualBox Host and Guest VMs
    • How to SSH to a VirtualBox guest externally through a host? [closed] – Code D3 on Setup SSH access between VirtualBox Host and Guest VMs
    • How to copy and paste from VirtualBox? [duplicate] on Setup SSH access between VirtualBox Host and Guest VMs
    • Jackie Laguna on Fix OpenGL: ChoosePixelFormat SketchUp error in WINE
    © 2025 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.