Entering edit mode
6.4 years ago
Sam
▴
150
Dear Biostars
I have two files and I want compare file 1 with column 4 of file 2 and print matched line file2 to file3. but I want keep the header line of file2 , so is it a correct code :
Thanks
cat <(head -n 1 file2) <(awk -F '\t' 'NR==FNR{a[$1]++;next} (a[$4])' file 1 file 2)> file3
File1
Position
45429
45567
45943
45965
45981
46123
46124
File 2
#rs alleles chrom pos strand assembly center protLSID assayLSID panelLSID QCcode A.02 A.18 A.25 A.27 A.30 A.31 A.36 A.38 A.43 A.47 AA.01 AA.02 AA.18 AA.21 AA.22 AA.23 AA.25 AA.27 AA.30 AA.31 AA.35 AA.363 AA.365 AA.366 AA.368 AA.37 AA.39 AA.45 AA.46 AA.47 MB.401.2 MB.401
Chr01_9671 C/T Chr01 9671 + NA GBS-SNP-CROP GBS RefName Custom QC+ Y C Y Y Y T Y T C Y T Y Y Y N Y Y T Y C T Y Y C C T Y Y C Y Y Y
Chr01_10594 A/T Chr01 10594 + NA GBS-SNP-CROP GBS RefName Custom QC+ W W W W W A W A T W A W W W W W W A W T A W W T T A W W T W W W
Please, care about the misspelling in your post and title.
Well, execute what you wrote. If it's not what you were expected, post what you want to obtain and we'll try to help you
sort your files and use join: https://linux.die.net/man/1/join
Your command line is actually working great on my machine
Please give feedback on your previous question(s):
If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.