I want to output two text files in two columns — one on the left side and other one on the right.
paste
doesn't solve the problem, because it only insert a character as delimiter, so if the first file has lines of different lengths output will be twisted:
$ cat file1
looooooooong line
line
$ cat file2
hello
world
$ paste file1 file2
looooooooong line hello
line world
If there was a command to add trailing spaces like fmt --add-spaces --width 50
the problem would be solved(1):
$ paste <(fmt --add-spaces --width 50 file1) file2
looooooooong line hello
line world
But I don't know a simple way to do this.
So how to merge files horizontally and print them to standard output without twisting?
In fact I just want to read them side-by-side.
(1) UPD: command to add trailing spaces does exist, e. g. xargs -d '\n' printf '%-50s\n'
.
But running
$ paste <(add-trailing-spaces file1) file2
won't produce expected visual output when file1
has fewer lines than file2
.
awk
for your hypotheticalfmt
command, see https://stackoverflow.com/a/9394541/1741542 as an awk – Olaf Dietsche Sep 16 '17 at 18:14