Finding common value across multiple files containing single column values

后端 未结 4 1203
温柔的废话
温柔的废话 2020-12-11 22:13

I have 100 text files containing single columns each. The files are like:

file1.txt
10032
19873
18326

file2.txt
10032
19873
11254

file3.txt
15478
10032
112         


        
4条回答
  •  一生所求
    2020-12-11 22:23

    awk to the rescue!

    to find the common element in all files (assuming uniqueness within the same file)

    awk '{a[$1]++} END{for(k in a) if(a[k]==ARGC-1) print k}' files
    

    count all occurrences and print the values where count equals number of files.

提交回复
热议问题