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?

Foam Seat Cushion

Aching back from coding all day? Try Back Problems

This foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.

$ Check price
99.9599.95Amazon 4.5 logo(9,445+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

Linux for Beginners

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

Linux for Beginners doesn't make any assumptions about your background or knowledge of Linux. You need no prior knowledge to benefit from this book. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand.

$ Check price
24.9924.99Amazon 4.5 logo(101+ reviews)

More Linux & UNIX resources

Ad