Reputation: 405
I have 4 files say:
cat test1
1
2
3
cat test2
4
5
6
cat test3
7
8
9
I need to display the content as below side by side:
1 4 7
2 5 8
3 5 9
I tried pr -m -t test1 test2 test3
, but if if any value is large, the output is getting trim, I need to display the content according to the length of the value and should display the content side by side(column wise)
Upvotes: 5
Views: 732
Reputation: 26955
Give a try to paste, for example:
$ cat test1 test2 test3 | paste -d " " - - -
From the man:
If
-
is specified for one or more of the input files, the standard input is used; standard input is read one line at a time, circularly, for each instance of-
.
So if you don't care about the order and let's say you would like to use all your *.txt
files, you could simply do:
$ paste -d " " *.txt
You could also use lam:
$ lam test1 -s " " test2 -s " " test3
Both examples use space as the separator " "
and will output:
1 4 7
2 5 8
3 6 9
Upvotes: 1
Reputation: 11
You can use this command which would not truncate the column values while printing:
pr -mJ test1 test2 test3 --sep-string=" || "
Upvotes: 1
Reputation: 1781
You can simple do it like :
cat *.txt | paste -d " " - - - | sed 's/_//g'
Upvotes: 2
Reputation: 1600
to complete nbari according your question:
paste test1 test2 test3 | column -t
P.S. for column greater than your screen size:
paste test1 test2 test3 | column -t| less -S
Upvotes: 0