Split output over columns

Problem

Ever wanted to produce columns of output, rather than your output spilling off the screen.



Solution

Useful command for this is paste, see example for how it works – to split output into 3 columns.



Example


ls | paste - - -
comments.php comments-popup.php fat.js
footer.php header.php index.php
screenshot.png sidebar.php style.css

As you'd expect with UNIX, that is not the end of this commands uses! 🙂

Create a comma seperated list:

ls | paste - - - -d,
comments.php,comments-popup.php,fat.js
footer.php,header.php,index.php
screenshot.png,sidebar.php,style.css

Then courtesy of the LINUX info command:


cat num2
1
2
$ cat let3
a
b
c
$ paste num2 let3
1 a
2 b
c

And:


$ paste -s num2 let3
1 2
a b c



Reference

[tags]paste, Unix Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *