gpt4 book ai didi

linux - shell 中两个文件的列差异

转载 作者:IT王子 更新时间:2023-10-29 00:47:52 26 4
gpt4 key购买 nike

我想做一件很简单的事情。我有两个文件如下:

FILE 1:
A s1 p1
B s2 p2
C s3 p3

FILE2:
B s4 p4
A s1 p1
C s6 p6

我想从文件中提取第一列和第三列并打印该文件的差异。一种简单的方法是使用两个文件的 cut -f1,3 创建中间文件并进行比较。这正是我想要的输出。但我不想创建中间文件。任何简单的衬垫都可以做到这一点。

还有一点,两个文件都没有排序,所以不能直接使用 join。

最佳答案

试试这个:

diff <(cut -f1,3 file1) <(cut -f1,3 file2)

引用资料:

Compare two files line by line and generate the difference in another file

关于linux - shell 中两个文件的列差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38372561/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com