I have two files. File 1 has a pattern in the form of a single column that I want to compare with all columns in file 2 to ultimately count how many columns in file 2 show that pattern. The number of columns in file 2 is very large (~300,000 columns). I am not sure if Unix solution is the best way to tackle this large number of columns. I have only been able to figure out how to match column 1 from file 1 with a specific column in file 2 using awk. How do I compare column 1 in file 1 to all columns in file 2?
Example: File 1
0
0
0
0
1
1
0
0
0
0
File 2:
0 0 0 0
0 0 0 1
0 0 0 0
0 0 0 1
0 1 1 0
0 0 1 1
0 1 0 0
0 0 0 0
0 0 0 0
0 0 0 1
I would like to store the matching columns in a separate file and count the number of columns in this new file. So for the above example, only column 3 from file 2 matches file 1 and the output would be column 3 in a new file and the count would be 1.