10

It is possible to print the result of 2 commands side by side...

Something like this

something `ls -l /a` `cat bla.txt`

result:

total 24                                                #while [ 1 = 1 ]; do
-rw-r--r-- 1 wolfy wolfy  194 Aug 13 08:50 c.in         #       echo "bla"
-rwxr-xr-x 1 wolfy wolfy   52 Sep 24 11:48 bla.sh       #done
-rwxr-xr-x 1 wolfy wolfy   38 Sep 24 11:48 bla1.sh      echo "bla"
-rwxr-xr-x 1 wolfy wolfy  147 Sep 24 11:54 ble.sh

I know that pr can do something like this with files, but I didn't find a way to do this for commands...

12

You can use process substitution

pr -m <(cmd1) <(cmd2)

though in your case, since you have one command and one file:

ls -l | pr -m - bla.txt
  • 1
    Instead of pr -m one can use paste. – Ramchandra Apte Oct 15 '13 at 15:39
  • 1
    @RamchandraApte yes, though paste won't align them in columns like pr -m does. – geirha Oct 15 '13 at 18:36
4

You can use screen like this:

In screen type Ctrl-a | for vertical and Ctrl-a S for horizontal split.

  • jump to next display region: Ctrl-a Tab
  • remove current region: Ctrl-a X
  • remove all regions but the current one: Ctrl-a Q

start ls -l /a in the right half and cat bla.txt in the left.

  • Where screen works, tmux works too. – kiri Oct 17 '13 at 13:45
3

TL;DR

Consider using a combination of paste / column rather than pr to get more consistent results.

  • Depending on your OS, pr incorrectly mixes in the columns when input lengths differ (Ubuntu, macOS) or even worse will print each input on a completely different pages (Centos 7)

  • pr both prepends and appends extraneous output

FORMAT:

paste <(cmd1) <(cmd2) | column -s $'\t' -t

Detailed Explanation

A highly robust solution is possible through a combination of the paste and column commands.

Advantages of the paste / column approach over pr:

  • Cleaner output due to no timestamp or page header information being prepended, nor a full screen of empty lines appended

  • Columns always stay separate even when the input lengths are different

Concrete example:

paste <(ls -1 .) <(ls -1 ..) | column -s $'\t' -t

Real-life output of paste / column technique on Ubuntu 16.04:

jay-z@jaytaylor.com:~/go/src/github.com/jaytaylor/html2text
$ paste <(ls -1 .) <(ls -1 ..) | column -s $'\t' -t
LICENSE            archiveify
README.md          go-hostsfile
html2text.go       html2text
html2text_test.go  jaytaylor
testdata           mockery-example
shipbuilder
stoppableListener
tesseract-web

See also: combine text files column-wise

For Comparison: pr on various platforms

TL;DR: pr behavior is inconsistent across Linux flavors.

Output of pr version on Ubuntu:

jay-z@jaytaylor.com:~/go/src/github.com/jaytaylor/html2text
$ pr -m <(ls -1 .) <(ls -1 ..)


2017-05-25 15:50                    /dev/fd/62                    Page 1


LICENSE                 archiveify
README.md               go-hostsfile
html2text.go                html2text
html2text_test.go           jaytaylor
testdata                mockery-example
                    shipbuilder
                    stoppableListener
                    tesseract-web

Output of pr version on OS X / macOs:

jay-z@jaytaylor.com:~/go/src/github.com/jaytaylor/html2text
$ pr -m <(ls -1 .) <(ls -1 ..)


May 25 08:55 2017  Page 1


LICENSE                 archiveify
README.md               go-hostsfile
html2text.go                html2text
html2text_test.go           jaytaylor
testdata                mockery-example
                    shipbuilder
                    stoppableListener
                    tesseract-web

<... remainder of screen filled with blank lines ...>

Output of pr version on Centos:

(Surprisingly the behaviour of pr under Centos 7 differs from that of all other platforms tested)

jay-z@jaytaylor.com:~/go/src/github.com/jaytaylor/html2text
$ pr <(ls -1 .) <(ls -1 ..)


2017-05-25 15:59                    /dev/fd/63                    Page 1


LICENSE
README.md
html2text.go
html2text_test.go
testdata

<... remainder of screen filled with blank lines ...>

2017-05-25 16:21                    /dev/fd/62                    Page 1


archiveify
go-hostsfile
html2text
jaytaylor
mockery-example
shipbuilder
stoppableListener
tesseract-web

<... remainder of screen filled with blank lines ...>
  • nice. better than the accepted answer. but still, colored output breaks everything. paste <(screenfetch) <(echo hi |cowsay -W 20) |column -s $'\t' -t – Blauhirn Jan 15 '18 at 17:57
  • Glad to hear you found it helpful. Cheers! – Jay Taylor Jan 16 '18 at 18:02
  • it is helpful but not working properly with colors. see above command. do you know what to do about this? thanks – Blauhirn Jan 16 '18 at 19:00
  • Yes, colors will always mess it up. Stripping colors beforehand from the input may do the trick, for examples see these resources: commandlinefu.com/commands/view/3584/… or unix.stackexchange.com/questions/140251/… – Jay Taylor Jan 16 '18 at 22:55
  • This is a more complete answer and should be the accepted answer. – Jeremy Iglehart Oct 17 '18 at 22:07

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.