Reputation: 66184
How can I attach the first column of a file to another file, using UNIX commands, etc.?
Example:
file1
-----
10 foo
20x bar
30 baz
file2
-----
obama
clinton
nixon
Result:
-------
10 obama
20x clinton
30 nixon
In my case, file1
and file2
are guaranteed to have the same numbers of lines.
Upvotes: 3
Views: 93
Reputation: 14768
Use cut
and paste
:
paste -d ' ' <(cut -d ' ' -f 1 file1) file2
Output:
$ paste -d ' ' <(cut -d ' ' -f 1 file1) file2
10 obama
20x clinton
30 nixon
Upvotes: 3