I have a file like this:
file 1:
1 2 0.000
1 3 0.213
1 4 0.014
1 5 0.001
1 6 0.555
1 7 0.509
1 8 0.509
3 4 0.995
3 5 0.323
3 6 0.555
3 7 0.225
3 8 0.000
4 5 0.095
4 6 0.058
4 7 0.335
4 8 0.000
5 6 0.995
5 7 0.658
5 8 0.000
6 7 0.431
6 8 0.000
7 8 0.000
and file 2 :
1
3
4
5 6 7
I want keep those rows in file 1 in which pair numbers are observed together in a row at file2. here only 5, 6 and 7 are observed together in file 2. therefore each pair of those numbers should be remained in file1. so out put is:
5 6 0.995
5 7 0.658
6 7 0.431
any suggestion(by considering that the real data is huge and numbers may not begin from 1) ?
perl
can be faster thanawk
, see benchmarks in my answer. – rudimeier Oct 6 '16 at 11:26awk
is usually faster thanperl
, but I feel like someone with better experience would be able to write aperl
solution much faster than mine :) – Sundeep Oct 6 '16 at 11:37