comparing two files and merge the data

Posted by Ganz Ricanz on Stack Overflow See other posts from Stack Overflow or by Ganz Ricanz
Published on 2013-11-09T21:17:29Z Indexed on 2013/11/09 21:54 UTC
Read the original article Hit count: 228

Filed under:
|
|
|
|

I have the below files,

total.txt

order1,5,item1
order2,6,item2
order3,7,item3
order4,6,item4
order8,9,item8

changed.txt

order3,8,item3
order8,12,item8

total.txt is total order data and changed.txt is recently changed data. I want to merge the recent change with total, i want the output as ,

Output.txt

order1,5,item1
order2,6,item2
order3,8,item3
order4,6,item4
order8,12,item8

Note : 2nd column of (3rd & 5th) row of the total.txt is updated with changed.txt file

i have used the below nawk to compare the first coulmn, but not able to print it to the output file. Please help on complete the below command

nawk -F"," 'NR==FNR {a[$1]=$2;next} ($1 in a) "print??"' total.txt changed.txt

© Stack Overflow or respective owner

Related posts about linux

Related posts about shell