Using paste to create columns from input data


I periodically need to take input data from various utilities and convert it to columnar data. There are a million ways to do this, but I have come to rely on the paste utility to perform this task:

$ ls

1 11 13 15 17 19 20 4 6 9
10 12 14 16 18 2 3 5 78

$ ls | paste - - -

1 10 11
12 13 14
15 16 17
18 19 2
20 3 4
5 6 78
9

In the output above, paste will take the input given to it and print the data in 3 columns (you can add more hyphens to get more columns of data). If anyone has some interesting little tidbits such as this, feel free to add them to the comments section. Thanks!

This article was posted by Matty on 2009-03-14 10:50:00 -0400 -0400