-3

I have a file that is in the following format:

6,test,A,B,C,D
6,test,A,B,C,F
7,test,A,B,C
7,test,A,B,D

I would like to write something that outputs the different columns. For example:

6 - column 6 is different
7 - column 5 is different

Columns will always be separated by a comma and the first column will always be the unique identifier among the rows.

user3299633
  • 2,971
  • 3
  • 24
  • 38

1 Answers1

1

awk to the rescue!

here is the prototype that works, fix the text for your needs

$ awk -F, '$1 in a{n=split(a[$1],p);
                   for(i=2;i<=n;i++) 
                       if(p[i]!=$i) print $1,i " different"; next}
                  {a[$1]=$0}' file

6 6 different
7 5 different
karakfa
  • 66,216
  • 7
  • 41
  • 56