I have two variables which are comma separated lists. I would like to join these two variables by appending the lines based on their unique id.
Example below:
var1="
id1,data1,data2,data3
id2,data1,data2,data3
id3,data1,data2,data3
id4,data1,data2,data3
"
var 2="
id1,data4,data5,data6
id2,data4,data5,data6
id3,data4,data5,data6
id4,data4,data5,data6
"
output="
id1,data1,data2,data3,data4,data5,data6
id2,data1,data2,data3,data4,data5,data6
id3,data1,data2,data3,data4,data5,data6
id4,data1,data2,data3,data4,data5,data6
"
I’m not the best at AWK and while I can decrypt it I still have troubles coming up with commands. If you could help that would be great!
If you’re not set on
sedorawk, you can usejoin:Use the
-a1 -a2options if you want to see unmatched lines, otherwise don’t.Note that the files need to be sorted, if they’re not already, you can use the
sortcommand for that.