Next: , Previous: Invoking tabfmt, Up: Top


3 Examples

tabfmt is particularly useful to convert various system configuration files to a more readable format.

     
     $ tabfmt /etc/mtab
     
     /dev/hda1	/            	ext3  	rw                   	0	0
     /dev/hda2	/tmp         	ext3  	rw,nosuid,nodev      	0	0
     /dev/hda3	/var         	ext3  	rw,nosuid,nodev      	0	0
     /dev/hda4	/usr         	ext3  	rw,nodev             	0	0
     /dev/hda5	/home        	ext3  	rw,nosuid,nodev      	0	0
     proc     	/proc        	proc  	rw                   	0	0
     sysfs    	/sys         	sysfs 	rw                   	0	0
     devpts   	/dev/pts     	devpts	rw,gid=5,mode=620    	0	0
     tmpfs    	/dev/shm     	tmpfs 	rw                   	0	0
     usbfs    	/proc/bus/usb	usbfs 	rw                   	0	0
     tmpfs    	/dev         	tmpfs 	rw,size=10M,mode=0755	0	0
     

This example splits /etc/mtab (which contains space-separated data), and outputs a tab-delimited table with constant-width columns. (You may not find tabs here if you are reading this manual in printed or HTML format.)

     
     $ awk -F: '( $7 == "/bin/false")' /etc/passwd |
     >   cut -d: -f1,3,4,5,6 |
     >   tabfmt -d: -w,,,15, -D\| -p1
     
      Debian-exim | 102 | 102   |                 | /var/spool/exim4
      sshd        | 100 | 65534 |                 | /var/run/sshd
      messagebus  | 101 | 104   |                 | /var/run/dbus
      hal         | 105 | 105   | Hardware abstra | /var/run/hal
      identd      | 103 | 65534 |                 | /var/run/identd
      gdm         | 104 | 107   | Gnome Display M | /var/lib/gdm
      ntop        | 109 | 109   |                 | /var/lib/ntop
      scanlogd    | 107 | 65534 |                 | /usr/lib/scanlogd
      cups-pdf    | 108 | 65534 | Anonymous Samba | /var/spool/cups-pdf
     

This example first uses awk to extract from /etc/passwd those accounts whose login shell is /bin/false. It then uses cut to print only the login name, uid, gid, user name and home directory. Finally, tabfmt is invoked to produce a human-readable table, truncating user names which exceed 20 characters in length.

     
     $ for f in README NEWS AUTHORS THANKS COPYING INSTALL ChangeLog; do
     >   echo -n $f:
     >   ls -1 /usr/share/doc/*/$f 2>/dev/null | wc -l
     > done | tabfmt -d: -al,r -D" = "
     
     README    = 443
     NEWS      =  13
     AUTHORS   = 262
     THANKS    =  51
     COPYING   =   1
     INSTALL   =   2
     ChangeLog =   0
     

This example demonstrates how to use tabfmt at the end of a pipeline gathering some file statistics. It uses the -a option to right-align the numbers, and the -D option to set the output delimiter to a `=' with spaces around it.