Easy way to columnize STDOUT (format text in columns)?

3

2

I just want an easy way to columnize output to the terminal.

  • Don't care about colors. (Well, actually I do quite a bit! But there is the awesome, easy-to-use ANSI Color for that.)
  • Shell scripts preferred, but anything easy-to-use will do.
  • Flexible solutions preferred, but the simple case I'd love to solve is just looking through text line-by-line, looking for the first occurrence of a separator (say, the equals sign, or maybe a comma), and separate everything on either side of that character into its own column.

Zearin

Posted 2011-06-08T14:36:18.000

Reputation: 229

Answers

11

Use the column command:

rpinson@rpinson:~$ mount | column -t
/dev/sda1         on  /                         type  ext3                   (rw,errors=remount-ro)
proc              on  /proc                     type  proc                   (rw,noexec,nosuid,nodev)
none              on  /sys                      type  sysfs                  (rw,noexec,nosuid,nodev)
none              on  /sys/kernel/debug         type  debugfs                (rw)
none              on  /sys/kernel/security      type  securityfs             (rw)
none              on  /dev                      type  devtmpfs               (rw,mode=0755)
none              on  /dev/pts                  type  devpts                 (rw,noexec,nosuid,gid=5,mode=0620)
none              on  /dev/shm                  type  tmpfs                  (rw,nosuid,nodev)
none              on  /var/run                  type  tmpfs                  (rw,nosuid,mode=0755)
none              on  /var/lock                 type  tmpfs                  (rw,noexec,nosuid,nodev)
none              on  /lib/init/rw              type  tmpfs                  (rw,nosuid,mode=0755)
binfmt_misc       on  /proc/sys/fs/binfmt_misc  type  binfmt_misc            (rw,noexec,nosuid,nodev)
gvfs-fuse-daemon  on  /home/rpinson/.gvfs       type  fuse.gvfs-fuse-daemon  (rw,nosuid,nodev,user=rpinson)

ℝaphink

Posted 2011-06-08T14:36:18.000

Reputation: 3 531

That was easy!! – Linker3000 – 2011-06-08T14:47:44.453

But beautiful :D – Pitto – 2011-06-08T16:33:42.473

Holy crap …that WAS easy! ☺ I can’t believe I haven’t heard of this awesome little program before. You, @Raphink , rock. – Zearin – 2011-06-10T12:44:45.963