我有两个文件。需要比较两个文件并通过 unix unix shell 脚本覆盖从 test2.txt 到 test1.txt 的值。 如果有的话 应该在test1中添加额外的键.txt
注意:只需要覆盖值而不是键。
测试1.txt
Name = krishna
Age =30
DOB = 30-Sep-94
Total Marks =375
测试2.txt
Name = Ram
Age =35
DOB = 23-Aug-95
Total Marks =300
Remarks = He is very good
预期盈亏
测试3.txt
Name = krishna
Age =30
DOB = 30-Sep-94
Total Marks =375
Remarks = He is very good
使用 awk:
$ awk 'BEGIN{FS=" *="}NR==FNR{a[$1]=$0;next}{print ($1 in a?a[$1]:$0)}' file1 file2
输出:
Name = krishna
Age =30
DOB = 30-Sep-94
Total Marks =375
Remarks = He is very good