CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
search file with input

 



cmccabe1
Novice

Sep 24, 2013, 7:32 AM

Post #1 of 3 (367 views)
search file with input Can't Post

Is it possible to search a text file using a search file?

For example, in the ($6 == 52) is it possible to use search_genes.txt, which is a bunch of gene names. Then all 70 of those genes names are searched in the input.txt column 6. If the gene name matches then column 9 of the data file and column 6 (gene name) are printed?


Code
awk -F, '{ if ($6 == 52) print $0 }' data.txt


Thank you.


BillKSmith
Veteran

Sep 24, 2013, 10:41 AM

Post #2 of 3 (361 views)
Re: [cmccabe1] search file with input [In reply to] Can't Post

Initialize a hash using the gene names as keys. (The values do not matter - use all 1's).

For each record of the data file:
Split into records
If field_6 exists in the hash, process the record.
Good Luck,
Bill


Laurent_R
Enthusiast / Moderator

Sep 25, 2013, 12:04 PM

Post #3 of 3 (345 views)
Re: [cmccabe1] search file with input [In reply to] Can't Post


In Reply To
Is it possible to search a text file using a search file?

For example, in the ($6 == 52) is it possible to use search_genes.txt, which is a bunch of gene names. Then all 70 of those genes names are searched in the input.txt column 6. If the gene name matches then column 9 of the data file and column 6 (gene name) are printed?


Code
awk -F, '{ if ($6 == 52) print $0 }' data.txt



Is this supposed to be a Perl question?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives