file1.txt
:
hi
wonderful
amazing
sorry
superman
superhumanwith
loss
file2.txt
:
1
2
3
4
5
6
7
When i try to combine using paste -d" " file1.txt file2.txt > actualout.txt
actualout.txt
:
hi 1
wonderful 2
amazing 3
sorry 4
superman 5
superhumanwith 6
loss 7
But i want my output to look like this
desired
OUT.txt
:
hi 1
wonderful 2
amazing 3
sorry 4
superman 5
superhumanwith 6
loss 7
Which command can be used to combine 2 files an look like the desired output?
Solaris 5.10
ksh
nawk, sed, paste
Best Answer
Note:
file1
is quite intentionally read twice; the first time is to find the maximum line length, and the second time is to format each line for the final concatenation with corresponding lines from file2. —file2
is read programatically; its name is provided by awk's variable-as-an-arg feature.Output:
To handle any number of input files, the following works.but *Note: it does not cope with repeating the same filename. ie each filename arg refers to a different file. It can, however, handle files of different lengths - beyond a files EOF, spaces are used.
Here is the output with 4 input files: