compare two columns in text files
0
0
Entering edit mode
5.8 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
awk cat • 1.3k views
ADD COMMENT
1
Entering edit mode

Please, care about the misspelling in your post and title.

so is it a correct code

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

ADD REPLY
1
Entering edit mode

sort your files and use join: https://linux.die.net/man/1/join

ADD REPLY
1
Entering edit mode

Your command line is actually working great on my machine

ADD REPLY
0
Entering edit mode

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.
Upvote|Bookmark|Accept

ADD REPLY

Login before adding your answer.

Traffic: 2575 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6