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
11254
and so on. The size of each file is different. Kindly tell me how to find the numbers which are common in all these 100 files.
Files with a single column?
You can sort and compare this files, using shell:
Last
-c
is not necessary, it's need only if you want to count number of occurences.This will work whether or not the same number can appear multiple times in 1 file:
The above uses GNU awk for true multi-dimensional arrays and ARGIND. There's easy tweaks for other awks if necessary, e.g.:
If the numbers are unique in each file then all you need is:
One using Bash and
comm
because I needed to know if it would work. My test files were1
,2
and3
, hence thefor f in ?
:awk
to the rescue!to find the common element in all files (assuming uniqueness within the same file)
count all occurrences and print the values where count equals number of files.