I have 2 text files, both have one simple, single column. The 2 files might be the same length, or might not, and if not, it's unknown which one would be longer.
For this example, file1 is longer:
---file1
Joe
Bob
Mary
Sally
Fred
Elmer
David
---file2
Tomato
House
Car
Elephant
All I want is to paste them side-by side into a new file like so:
No logic, no matching - just a simple paste, with a simple tab formatting to separate the 2 columns.
---file3
Joe Tomato
Bob House
Mary Car
Sally Elephant
Fred
Elmer
David
I've tried the "paste" command, like "paste file1 file2 > file3" but it works works only if file1 is longer than or the same length as file2. If file2 is longer, the extra values are misaligned too far over to the left and appear to belong to file1 as follows:
---file3
Tomato Joe
House Bob
Car Mary
Elephant Sally
Fred
Elmer
David
Also tried this awk I found in the forums, but it works only if file1 is longer or same length as file2 - it truncates file2 if file1 is shorter.
awk 'NR==FNR{_[NR]=$0;next}{print $1,$2,_[FNR]}' file2 file1
---file3
Tomato Joe
House Bob
Car Mary
Elephant Sally
I don't care if the solution is awk, sed, shell script, or what.
Reading both files into an array might be the solution, but I don't know enough on how to write the code for that.
Any help is greatly appreciated, thanks!