7

I'm sure it's very simple, but I can't remember how to tell a terminal pager (more/less/pg/most) to display a long list in columns.

Since my input is just a list of short elements, displaying it the same way ls does it by default would save me needless scrolling and precious screen real estate.

bad:

aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii

good:

aaa ddd ggg
bbb eee hhh
ccc fff iii

3 Answers 3

12

Use column.

Example:

ls -1 | column -c 100

This will format the output of ls -1 (one entry per line) to fit as many columns of equal size as possible in rows that are 100 character wide.

0

You can use paste to join lines from stdin:

paste - - - < filename
0

Similar to Daniel Beck's answer:

$ echo {a..c}{a..c}{a..c}| tr \  \\n | column | sed 's/\t/ /g' | $PAGER
aaa aba aca baa bba bca caa cba cca
aab abb acb bab bbb bcb cab cbb ccb
aac abc acc bac bbc bcc cac cbc ccc

The key is to make the output more compact by substituting tabs with spaces.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.