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.
我正在使用 join -1 2 -2 2 file1.txt file2.txt > file3.txt基于它们的第二列加入我的两个文本文件并将它们写入 file3.txt,它工作得很好。但是,我不希望 file3.txt 包含公共字段。谷歌搜索和加入的man页面表明-o格式化运算符可以帮助实现这一点,但我应该如何去做呢?
join -1 2 -2 2 file1.txt file2.txt > file3.txt
man
-o
假设每个文件只有两列,并且您想加入第二列但在输出中只显示每个文件的第一列,请使用
join -1 2 -2 2 -o 1.1,2.1 file1.txt file2.txt > file3.txt
请记住,在加入之前,您的两个文件应在第二列上排序。
运行示例:
$ cat file1.txt 2 1 3 2 7 2 8 4 2 6 $ cat file2.txt 3 1 5 4 9 9 $ join -1 2 -2 2 -o 1.1,2.1 file1.txt file2.txt 2 3 8 5