1

Compare multiple columns from 2 files

view story
linux-howto

http://www.unix.com – Hi, I need to compare multiple columns from 2 files. I can, for example, have these 2 files: file1: Code: col1, col2, col3,col4 a,1,4,7 b,2,5,8 c,3,6,9 file2: Code: col1, col2, col3,col4 a,2,3,2 b,5,7,5 c,1,9,8 As a result, I need for example the difference between the columns 2 and 4: Code: col2, col4 1,-5 3,-3 -2,-1 I made something that works for comparing 1 column, but I wonder if it's possible to make it work for multiple columns: Code: nawk -F, 'FNR==NR{a[$1]=$3;next}{print $3-a[$1]}'  file1 file2 (HowTos)