12

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...

Wolfy
  • 8,050

3 Answers3

14

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
geirha
  • 47,279
6

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 ...>
5

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.

gertvdijk
  • 69,427
chaos
  • 28,186