Given these two files
file1.txt
------
foo
bar
file2.txt
------
foo 1
foo 2
bar 31
How can I obtain the first line of successful join in file2.txt?
The expected result after joining is:
foo 1
bar 31
I tried this but didn’t work:
join file1.txt file2.txt
What’s the right join command?
The join you tried will print both instances of
foofromfile2. If you want to pick only one, you could usesortto ensure there are unique entries in both files before you do the actual join: