06. Column Editing and Pretty Printing column, colrm, fold

Pretty printing

The column command is the "pretty-print" of the command line. It formats its input into multiple columns.

-c
Specify how wide each column should be.
-s
Specify set of characters
-t
Determine number of columns the input contains and create a table. Columns delimited by whitespace or the characters specified with the -s option.
-x
Fill columns before filling rows.

Column removal

The colrm command removes a range of columns from standard in or a file.

$ cat birthdates.txt
05/24/1999,4
04/23/1974,2
08/09/2001,5
11/24/1991,3
01/23/1975,1
$ colrm 3 5 < birthdates.txt
# remove from column 3 to 5
05/1999,4
04/1974,2
08/2001,5
11/1991,3
01/1975,1
$ colrm 6 < birthdates.txt
# remove from column 6 onward.
05/24
04/23
08/09
11/24
01/23

Files with tabs

When working with files containing tabs, be sure to convert to spaces using the expand command first - otherwise, some unexpected behavior may occur.

Max-width with fold

The fold command makes long lines more readable by placing a new line every n characters.

To set n, use the -w option.

For example, take a look at a Lorem Ipsum text, which has no line breaks.

$ cat lorem.txt
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur dignissim venenatis pede. Quisque dui dui, ultricies ut, facilisis non, pulvinar non, purus. Duis quis arcu a purus volutpat iaculis. Morbi id dui in diam ornare dictum. Praesent consectetuer vehicula ipsum. Praesent tortor massa, congue et, ornare in, posuere eget, pede.

With the fold command we can break it up into lines with a width value of 45.

$ fold -w 45 lorem.txt
Lorem ipsum dolor sit amet, consectetuer adip
iscing elit. Curabitur dignissim venenatis pe
de. Quisque dui dui, ultricies ut, facilisis
non, pulvinar non, purus. Duis quis arcu a pu
rus volutpat iaculis. Morbi id dui in diam or
nare dictum. Praesent consectetuer vehicula i
psum. Praesent tortor massa, congue et, ornar
e in, posuere eget, pede.

This way, we are able to set a default width to our files for better readability.

Aching back from coding all day?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

System Admin Handbook

Take your Linux skills to the next level! Try Linux & UNIX

This book approaches system administration in a practical way and is an invaluable reference for both new administrators and experienced professionals. It details best practices for every facet of system administration, including storage management, network design and administration, email, web hosting, scripting, and much more.

$ Check price
74.9974.99Amazon 4.5 logo(142+ reviews)

More Linux & UNIX resources

Ad