gpt4 book ai didi

linux - 使用 awk 或 sed 比较两个文件的值并将文件 2 到文件 1 的信息附加到新文件 file3

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

我有 2 个文件:文件 1 和文件 2。我想检查并比较文件 1 和文件 2 中的文件名以及它们匹配的位置,仅使用 awk 或 sed 将 file_2 中的数字插入到新的 File_3 中的 file_1 中。

我尝试过使用

cat file.2 | while read line do 

The files 1 and 2 with expected output

最佳答案

试试这个:

awk 'NR==FNR { d[$NF]=$1; next } d[$NF] { print d[$NF] FS $0 }' FILE2 FILE1

关于linux - 使用 awk 或 sed 比较两个文件的值并将文件 2 到文件 1 的信息附加到新文件 file3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50073850/

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