Grep? - using a file of terms to search another file when the information is on a different line | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Grep? - using a file of terms to search another file when the information is on a different line

UNIX for Dummies Questions & Answers


Tags
grep, search file

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-14-2013
Twinklefingers Twinklefingers is offline
Registered User
 
Join Date: May 2011
Last Activity: 6 October 2014, 11:00 AM EDT
Location: Maryland, USA
Posts: 32
Thanks: 15
Thanked 0 Times in 0 Posts
Grep? - using a file of terms to search another file when the information is on a different line

I have a flat file that looks like this, let's call it Chromosome_9.txt:

Code:
FT                   /Gene_Name="Guanyl-Acetylase 9"
FT                   /Gene_Number"36952"
FT                   /Gene_Name="Endoplasmic Luciferase"
FT                   /Gene_Number"36953"
FT                   /Gene_Name="Variant Antigen Protein 12"
FT                   /Gene_Number"36954"
FT                   /Gene_Name="Acyl-CoA Synthetase 11"
FT                   /Gene_Number"36955"
FT                   /Gene_Name="Conserved protein, unknown function"
FT                   /Gene_Number"36956"

This is a file in a specialized format that contains all the information about genes on a chromosome, including the names and associated numbers. What I have is a list of numbers ("/Gene_Number," above), like this, let's call it gene_names.txt:
Code:
2568
3658
9567
23657
63654
76532

but I need the names associated with those numbers (on the line above the number in the file). This would be trivial is they were on the same line because then I could use:
Code:
grep -f gene_names.txt Chromosome_9.txt

Because the search term and the actual information I am looking for are on different lines, I am not sure what to do.

Thanks!
Sponsored Links
    #2  
Old 08-14-2013
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 28 November 2014, 5:50 AM EST
Location: Zürich
Posts: 8,489
Thanks: 333
Thanked 1,050 Times in 916 Posts
Does your grep support the -B option?
Sponsored Links
    #3  
Old 08-14-2013
Twinklefingers Twinklefingers is offline
Registered User
 
Join Date: May 2011
Last Activity: 6 October 2014, 11:00 AM EDT
Location: Maryland, USA
Posts: 32
Thanks: 15
Thanked 0 Times in 0 Posts
It does, but I don't know how to combine -f with -B
    #4  
Old 08-14-2013
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 28 November 2014, 5:50 AM EST
Location: Zürich
Posts: 8,489
Thanks: 333
Thanked 1,050 Times in 916 Posts

Code:
grep -B1 -f ...

The Following User Says Thank You to Scott For This Useful Post:
Twinklefingers (08-14-2013)
Sponsored Links
    #5  
Old 08-14-2013
Twinklefingers Twinklefingers is offline
Registered User
 
Join Date: May 2011
Last Activity: 6 October 2014, 11:00 AM EDT
Location: Maryland, USA
Posts: 32
Thanks: 15
Thanked 0 Times in 0 Posts
Thanks, worked like a charm
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep multiple search terms with context Moe.Wilensky Shell Programming and Scripting 1 04-20-2012 05:52 PM
Grep'ing information from a log file on SUN OS 5 illgetit Shell Programming and Scripting 5 11-20-2011 12:37 PM
Find common terms in two text file, xargs, grep eon Shell Programming and Scripting 15 10-12-2011 04:41 AM
copying file information using awk & grep nrjrasaxena Shell Programming and Scripting 6 10-09-2011 06:18 PM
Script to search a large file with a list of terms in another file dougzilla Shell Programming and Scripting 3 06-29-2010 06:19 PM



All times are GMT -4. The time now is 06:55 AM.