For a project that I'm working on, I need a list of identifiers which needs to match specifically a certain pattern.

I basically have a list of patterns in a file, and I want to grep with this file in another file to pick out the relevant lines.

Fortunately, grep -f patternfile.txt otherfile.txt > releventlinesfile.txt does not work. A grep -w neither.

The file structure of otherfile.txt is:

test_id gene_id gene    locus   sample_1        sample_2        status  value_1 value_2 log2(fold_change)       test_stat       p_value q_value significant   
TSS10019        XLOC_007800     ABC73140       1:27498963-27503819     BA  BB  NOTEST  0.666344        0.628569        -0.0841946      0       1       1       no
TSS1002 XLOC_000726     ABC14350       1:4907952-4913152       BA  BB  NOTEST  0       0       0       0       1       1       no
TSS10020        XLOC_007801     ABC73150       1:27504093-27506154     BA  BB  OK      11.8553 13.3817 0.174729        1.26968 0.02755 0.107242        no
TSS10021        XLOC_007802     ABC73165       1:27508724-27508949     BA  BB  NOTEST  0       0       0       0       1       1       no
TSS10022        XLOC_007803     ABC73170       1:27511324-27514797     BA  BB  OK      0.893787        0.557083        -0.682037       -0.590335       0.33135 0.575735      -no

And filestructure of patternfile.txt is:


The output that I want:

TSS10020        XLOC_007801     ABC73150       1:27504093-27506154     BA  BB  OK      11.8553 13.3817 0.174729        1.26968 0.02755 0.107242        no
  • Edit your question and add example chucks from both files and your desired output from that. – heemayl Sep 19 '16 at 8:42
  • The grep -f would correspond to making an array in awk to test for existence, but the example in awk does not show this. – Thomas Dickey Sep 19 '16 at 8:47
  • Please post two small example file contents and state what you want to achieve. Perhaps there are better methods than awk or grep. – Alexander Sep 19 '16 at 8:50
  • @ThomasDickey I thought as well that the grep -f would let the tss_lijst.txt file be the pattern file to be used in grep. What else could I have done, to make sure it does? – Dymphy Sep 19 '16 at 8:54
  • 1
    please sum up to "I have FILEA like .. and FILEB like ..., I want to join on ... giving FILEC like ...". here is what I tried ... – Archemar Sep 19 '16 at 9:27

You need to combine both the -w and -f options of grep in order to only match whole words and not get partial matches in your results:

grep -wf patternfile.txt otherfile.txt > releventlinesfile.txt 

I am a bit confused by the number of file.

  • lijst_expressie.txt
  • sig_splicing.txt
  • splicing.diff
  • tss_group_exp.diff
  • tss_lijst.txt

to boil down :

I want to find TSS from lss_lijst.txt in splicing.diff

using a short list : tss_lijst.txt


and the splicing.diff you gave, you can extract TSS listed in file1 using

awk 'NF==1{ tss[$1]=1 ; next ; } $1 in tss { print ;}' tss_lijst.txt splicing.diff
TSS1    XLOC_000001     AT1G01010       1:3630-5899     BAY_ST  BAY_LP  OK      0       0       0.219269        0       0.1726  0.474413        no
TSS10   XLOC_000007     AT1G01180       1:75404-76921   BAY_ST  BAY_LP  OK      0       0       0.0277474       0       0.77985 0.900632        no

to get the yes

awk '$14 == "yes" ' splicing.diff
  • That is incorrect. I want to find the AS events (from splicing.diff) in the DE genes (tss_group_exp.diff). (So, if it can be done with another method, that is fine by me) So: I want a tss_id with a 'yes' in both splicing.diff and tss_group_exp.diff. – Dymphy Sep 19 '16 at 9:22
  • Edited for clarity. I assume it is now clearer? – Dymphy Sep 19 '16 at 9:24

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.