I am new to awk and trying to write code which can merge 2 files..
File1
session=123;1,code=01,name=om
session=345;3,code=04,name=ra
File2
time=44,minute=22,sec=01,session=123;1,creation=89
time=34,minute=12,sec=023,session=523;1,creation=80
Output should be
time=44,minute=22,sec=01,session=123;1,creation=89,code=01,name=om
time=34,minute=12,sec=023,session=523;1,creation=80,,
I have written something like:
BEGIN { FS = OFS = "," }
FNR == NR {
a[$2] = substr($0,index($0,$2));
next
}
{
if($4 in a)print $0","a[$2];
else print $0",,";
}
But this does not generate the correct output.
Could you please help where I was mistaken?
file1
included in the expected output? Are there really supposed to be multiplesession
values on the same line infile1
? – Barmarfile1
before you edited. – Barmar