使用映射文件更改列的名称

时间:2020-03-01 18:42:05

标签: shell file dictionary unix awk

我有一个包含3列的文件:

NC_0001 10 x
NC_0001 11 x
NC_0002 90 y

我想使用另一个包含转换的文件.txt来更改第一列的名称,就像这样:

NC_0001 1
NC_0001 1
NC_0002 2

...

所以最后我应该有:

1 10 x
1 11 x
2 90 y

我该怎么做? 附言第一个文件非常大(50 GB),因此我必须使用awk之类的unix命令。

1 个答案:

答案 0 :(得分:1)

diff
awk -f script.awk map_file data_file

单线

NR == FNR {                  # for the first file
    tab[$1] = $2             # create a k/v of the colname and rename value
}

NR != FNR {                  # for the second file
    $1 = tab[$1]             # set first column equal to the map value
    print                    # print
}

如果可能,应该拆分第一个文件并在每个分区文件上并行运行此命令。然后,加入结果。

相关问题