unix - Fastest way to match column from one file to another -


i have 2 files both have on million lines , want print out match first column of file 1 second of file 2.

file_1

snp_a-2131660   1   0.0021 snp_a-1967418   2   0.0005 snp_a-1969580   2   0.0011 snp_a-4263484   1   0.0024 snp_a-1978185   0   0.0014 snp_a-4264431   0   0.0038 snp_a-1980898   2   0.0050 snp_a-1983139   0   0.0011 

file_2

"affx-snp_10000979" "rs4147951" "affx-snp_10009702" "rs2022235" "snp_a-2131660" "rs6425720" "affx-snp_10021569" "rs12997193" "affx-snp_10026879" "rs9933410" "affx-snp_10029725" "rs7142489" "affx-snp_10034687" "rs1350088" 

matches.txt

"snp_a-2131660" "rs6425720" 

right doing, slow. there faster way?

awk '{print $1}' file_1 | while read -r a; grep -h $a file_2; done >> matches.txt 

could please try following awk.

awk 'fnr==nr{a[$1]=$0;next} {val=$1;gsub(/\"/,"",val)} (val in a)' file_1 file_2 

if want redirect above command's output output file > output.txt(or whatever name output file) @ end of command too.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

linux - Why does bash short curcuit fail in crontab? -