gawk - awk to match two files and output the difference with column name & value -
i want compare 2 files awk , output unmatched columns.
what have tried till
awk -f',' 'fnr==nr{ for(i=0;i<=nf; i++){ a[i]; }next; } (i=1;i<=nf;i++){ if($i in a){ {printf("match: %s , col-> %d" $i,i-1)} else {printf("un- match: %s , col-> %d" $i,i-1) } } }'
but 1 of no use.
here need.
example: file 1 1,2,3,4,5,6 file 2 1,2,5,4,5,7 output col 3 -> 3,5 col 6 -> 6,7
awk, work more rows well
awk -f, 'nr==fnr{for(i=1;i<=nf;i++)a[nr,i]=$i;next} {for(i=1;i<=nf;i++)if(a[fnr,i]!=$i)print "row:"fnr,"col:"i"->",a[fnr,i]","$i}' file{1,2}
example
input
file1
1,2,3,4,5,6 6,5,4,3,2,1
file2
1,2,5,4,5,7 6,4,4,3,1,1
output
row:1 col:3-> 3,5 row:1 col:6-> 6,7 row:2 col:2-> 5,4 row:2 col:5-> 2,1
Comments
Post a Comment