群里的朋友求助:

$ cat file1
a 1 2 3
b 2 3 4
c 3 4 5

$ cat file2
d 你
b 好
c 吗

合并两个文件,需要实现:

a 1 2 3
b 2 3 4 好
c 3 4 5 吗
d         你

 

代码如下:

awk 'NR==FNR{a[$1]=$2;next}{if($1 in a){print $0,a[$1];delete a[$1]}else print}END{for(i in a)print i"\t"a[i]}' file2 file1

 

相关文章:

  • 2022-12-23
  • 2022-02-14
  • 2021-12-29
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
猜你喜欢
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
相关资源
相似解决方案