-1

I am having two files. Need to compare two files and overwrite the values from test2.txt to test1.txt by unix unix shell script. If anything Extra keys that should be added in test1.txt

Note: Need to overwrite only values not keys.

test1.txt

Name = krishna
Age =30
DOB = 30-Sep-94
Total Marks =375

test2.txt

Name = Ram
Age =35
DOB = 23-Aug-95
Total Marks =300
Remarks = He is very good

Expected o/p

Test3.txt

Name = krishna
Age =30
DOB = 30-Sep-94
Total Marks =375
Remarks = He is very good
oguz ismail
  • 1
  • 16
  • 47
  • 69

1 Answers1

1

Using awk:

$ awk 'BEGIN{FS=" *="}NR==FNR{a[$1]=$0;next}{print ($1 in a?a[$1]:$0)}' file1 file2

Output:

Name = krishna
Age =30
DOB = 30-Sep-94
Total Marks =375
Remarks = He is very good
James Brown
  • 36,089
  • 7
  • 43
  • 59