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



cmccabe1
Novice

Sep 24, 2013, 7:32 AM


Views: 2164
search file with input

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


Views: 2158
Re: [cmccabe1] search file with input

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
Veteran / Moderator

Sep 25, 2013, 12:04 PM


Views: 2142
Re: [cmccabe1] search file with input


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?