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
One using Bash and comm
because I needed to know if it would work. My test files were 1
, 2
and 3
, hence the for f in ?
:
f=$(shuf -n1 -e ?) # pick one file randomly for initial comms file
sort "$f" > comms
for f in ? # this time for all files
do
comm -1 -2 <(sort "$f") comms > tmp # comms should be in sorted order always
# grep -Fxf "$f" comms > tmp # another solution, thanks @Sundeep
mv tmp comms
done