gpt4 book ai didi

xml - 如何在一个相应的列上加入两个单独的文件?

转载 作者:太空宇宙 更新时间:2023-11-04 12:14:02 24 4
gpt4 key购买 nike

我试图在一列上连接两个文件,但连接和排序命令给我以下输出:

join: file 1 is not in sorted order

文件 1:

TEST->Infrastructure->Global Windows Server, OI-QASDWDASDWQWD,
TEST->Infrastructure->Global Windows Server, OI-WASDWDASDWWWW,
TEST->Infrastructure->zSeries_MVS, REGAA638G0K,
TEST->Infrastructure->zSeries_MVS, REGAA55410K,

文件 2:

SERVER1; Deployed; REGAA638G0K;
SERVER2; Deployed; OI-WASDWDASDWWWW;
SERVER3; Delete; OI-QASDWDASDWQWD;
SERVER4; Delete; REGAA55410K;

预期文件 3:

SERVER1; Deployed; TEST->Infrastructure->zSeries_MVS;
SERVER2; Deployed; TEST->Infrastructure->Global Windows Server;
SERVER3; Delete; TEST->Infrastructure->Global Windows Server;
SERVER4; Delete; TEST->Infrastructure->zSeries_MVS;

我的命令:

join -1 2 -2 3 -o 1.1,2.1,2.2 <(sort -t"," -k2 spmGroupsModifiedSCLine.out) <(sort -t";" -k3 spmCompStatJoined.out)

第一个文件中的第二列和第二个文件中的第三列相同,所以我尝试加入它并先对其进行排序。您是否看到其他方式进行连接?谢谢!

最佳答案

Awk解决方案:

awk 'NR==FNR{ a[$2]=$1; next }$3 in a{ print $1,$2,a[$3] }' FS=',' file1 FS=';' OFS='; ' file2

输出:

SERVER1;  Deployed; TEST->Infrastructure->zSeries_MVS
SERVER2; Deployed; TEST->Infrastructure->Global Windows Server
SERVER3; Delete; TEST->Infrastructure->Global Windows Server
SERVER4; Delete; TEST->Infrastructure->zSeries_MVS

关于xml - 如何在一个相应的列上加入两个单独的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47943122/

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