gpt4 book ai didi

linux - 加入原始排序文件,在一个文件中包含 2 个字段,在第二个文件中包含 1 个字段

转载 作者:太空宇宙 更新时间:2023-11-04 09:20:34 25 4
gpt4 key购买 nike

我需要有关 linux 命令的帮助。我有 2 个文件 StockSort 和 SalesSort。它们被排序,每个有 3 个字段。我知道如何对第一个文件中的 1 个字段和第二个文件中的 1 个字段进行排序。但是我无法获得正确的语法来连接第一个文件中的两个字段和第二个文件中的 1 个字段。我还需要将它保存在新文件中。到目前为止我有这个命令,但它不起作用。我认为错误在“2,3”部分,我需要从第一个文件中组合两个字段。

join -1 2,3 -2 2 StockSort SalesSort >FinalReport

StockSort file
3976:diode:350
4105:resistor:750
4250:resistor:500

SalesSort file
3976:120:net
4105:250:chg
5500:100:pde

Output should be like this:
3976:350:120
4105:750:250
4250:500:100

最佳答案

你可以试试

join -t: -o 1.1,1.3,2.2 stocksort salesort 

在哪里

-t set the column separator
-o is the output format (a comma sep. list of filenumber.fieldnumber)

关于linux - 加入原始排序文件,在一个文件中包含 2 个字段,在第二个文件中包含 1 个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42429558/

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