Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
鉴于这两个文件
file1.txt ------ foo bar file2.txt ------ foo 1 foo 2 bar 31
如何获取file2.txt中成功加入的第一行?加入后的预期结果是:
foo 1 bar 31
我试过这个但没有奏效:
join file1.txt file2.txt
什么是正确的加入命令?
您尝试的连接将打印foofrom的两个实例file2。如果您只想选择一个,则可以sort在执行实际连接之前确保两个文件中都有唯一的条目:
foo
file2
sort
join <(sort file1) <(sort -k1,1 -u file2)