merge two files by key if exists in the first file / bash script
bash, file, join, merge, unix
Solution
Join can do this, have you considered the `-a` option ? It will produce a line for each unpairable file line in a.txt and b.txt.
join -a1 a.txt b.txt
man01 xxx yyy zzz sss
man02 xxx yyy zzz
man03 xxx yyy zzz
man04 xxx yyy zzz
Problem
i have two files with columns sorted by the value of the first column, and i want to merge them only if the value of the second exists in the first one. The first file is like this ``` man01 xxx yyy zzz man02 xxx yyy zzz man03 xxx yyy zzz man04 xxx yyy zzz ``` The second file ``` man01 sss man08 sss ``` And the desired output is ``` man01 xxx yyy zzz sss man02 xxx yyy zzz man03 xxx yyy zzz man04 xxx yyy zzz ``` I tried join but requires values of second file exist in the first one :/