0

I am trying to use a .txt file with around 5000 patterns (spaced with a line) to search through another file of 18000 lines for any matches. So far I've tried every form of grep and awk I can find on the internet and it's still not working, so I am completely stumped.

Here's some text from each file.

Pattern.txt

rs2622590
rs925489
rs2798334
rs6801957
rs6801957
rs13137008
rs3807989
rs10850409
rs2798269
rs549182

There's no extra spaces or anything.

File.txt

snpid hg18chr bp a1 a2 zscore pval CEUmaf
rs3131972       1       742584  A       G       0.289   0.7726  .
rs3131969       1       744045  A       G       0.393   0.6946  .
rs3131967       1       744197  T       C       0.443   0.658   .
rs1048488       1       750775  T       C       -0.289  0.7726  .
rs12562034      1       758311  A       G       -1.552  0.1207  0.09167
rs4040617       1       769185  A       G       -0.414  0.6786  0.875
rs4970383       1       828418  A       C       0.214   0.8303  .
rs4475691       1       836671  T       C       -0.604  0.5461  .
rs1806509       1       843817  A       C       -0.262  0.7933  .

The file.txt was downloaded directly from a med directory.

I'm pretty new to UNIX so any help would be amazing!

This is copied from stackoverflow. I have tried every single thing that's been recommended but the output is still blank. Am I maybe missing a syntax issue or something in my text files?

P.S. Things I've tried:

grep -Fw -f Pattern.txt File.txt
fgrep -f Pattern.txt File.txt

FILENAME=$1
awk '{kount++;print   $0}' $FILENAME | fgrep -f - Pattern.txt

awk 'NR==FNR{pats[$0]; next} $2 in pats' Pattern.txt File.txt

closed as off-topic by jasonwryan, Bernhard, Anthon, Michael Homer, garethTheRed Nov 27 '14 at 8:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question has been posted on multiple sites. Cross-posting is strongly discouraged; see the help center and community FAQ for more information." – jasonwryan, Bernhard, Anthon, Michael Homer, garethTheRed

  • 2
    Please show us what you have tried. – cuonglm Nov 27 '14 at 6:12
  • Crossposted stackoverflow.com/questions/27163970/… – jasonwryan Nov 27 '14 at 6:30
  • @BananaMannock Why your output is blank? Because you don't have a same pattern inside Pattern.txt file from your File.txt. For testing, add rs12562034 in your Pattern.txt file and try the commands given for you and you will luck ;) – αғsнιη Nov 27 '14 at 16:55
2

Try this with GNU grep:

grep -f Pattern.txt File.txt

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