0

I have two files.

file A :

       Chr1     Cufflinks     exon    2903   3268   .   +   .   gene_id "XLOC_000001"; transcript_id "TCONS_00000002"; exon_number "1"; oId "CUFF.1.2"; tss_id "TSS1";

       Chr1     Cufflinks     exon    3354   3616   .   +   .   gene_id "XLOC_000001"; transcript_id "TCONS_00000002"; exon_number "2"; oId "CUFF.1.2"; tss_id "TSS1";

       Chr1     Cufflinks     exon    4357   4455   .   +   .   gene_id "XLOC_000001"; transcript_id "TCONS_00000761"; exon_number "3"; oId "CUFF.1.2"; tss_id "TSS1";

file B;

TCONS_00000066
TCONS_00000600
TCONS_00000761
TCONS_00000762
TCONS_00000773

I want to match the B file to and print where ever match is there. In this case the id in file A is in 12th column.

the output should be like

    Chr1    Cufflinks   exon    4357    4455    .   +   .   gene_id "XLOC_000001"; transcript_id "TCONS_00000761"; exon_number "3"; oId "CUFF.1.2"; tss_id "TSS1";

the whole line from file A should be in file C

I tried awk commands but failed.

awk 'FNR==NR {a[$12];next}; !($12 in a)' B A >C

Please help.

3
grep -fB A

will do what you're looking for; the -foption specifies a file from which patterns are loaded, one pattern per line. Any line in A which matches a pattern in B will be output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.