Visit Our UNIX and Linux User Community


Search specific name in a file and fetch specific entries


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search specific name in a file and fetch specific entries
# 1  
Old 10-16-2012
Search specific name in a file and fetch specific entries

Hi all,

I have 2 files, One file contain data like this


Code:
FHIT 
CS 
CHRM1 
PDE3A 
PDE3B 
HSP90AA1 
PTK2 
HTR1A 
ESR1 
PARP1 
PLA2G1B

These names are mentioned in the second file(Please see attached second file) as

# Drug_Target_X_Gene_NameWhere X can be any number (1-1000)

Now the second file contain data like this where these entries (Drug_Target_X_Gene_Name) are present

#BEGIN_DRUGCARD DB0xxxx (0001- 8820)

# Drug_Target_X_Gene_Name

Description

#END_DRUGCARD DB0xxxx (0001- 8820)



So, if any entry of first file matches with second file

Drug_Target_X_Gene_Name

I want to fetch following entry in a separate file

# Description:

So, if the CHRM1 from first file is present in Drug Card 00001 of second file as # Drug_Target_X_Gene_Name
the output shuld be



Code:
CHRM1       (Description in front like thid for eg: Lepirudin is identical to        natural hirudin except for substitution of  .....)

It is also possible CHRM1 is present in more than one drug cards, in that case there will be two different descriptions from two different drug cards



Code:
CHRM1       (Description in front like this for eg: Lepirudin is identical to        natural hirudin except for substitution of  .....) 
CHRM1       (Description in front like this for eg: Dornase alfa is a biosynthetic form of human deoxyribunuclease I (DNase I) enzyme. It is produced in genetically modified    Chinese hamster ovary   .....)

In same way for all entries of first file I need description from drug cards of second file if these entries are present in any of the drug card of second file.

Any help will be really appreciated.
# 2  
Old 10-17-2012
Have you tried using

Code:
grep -f file1 file2

# 3  
Old 10-17-2012
Request to check

Hi

Thanks for reply. I am matching a specific entry to fetch the description heading details only for each drug card if entry will match that why I think I have to use some other commands as well

Kindly guide if possible.

Mani
# 4  
Old 10-17-2012
Quote:
Originally Posted by manigrover
Hi

Thanks for reply. I am matching a specific entry to fetch the description heading details only for each drug card if entry will match that why I think I have to use some other commands as well
I think you have given wrong files. There is no match between those two files..
# 5  
Old 10-18-2012
Request to check

Hi

Thanks for reply. Both of the files are big. The first file contain 137 entries but the second file is very very big therefore I have part of it here.

If you can have a look on the attached second file on page 11, it is mentioned as

# Drug_Target_1_Gene_Name:
F2


these entries has to be matched with firs file and if matched I have to fetch #description , #indication and # pharmacology headings of that Drug card in which it is matched because each drug card contain moret han one

# Drug_Target_X_Gene_Name

but only once #description , #indication and # pharmacology headings .

Kindly guide if possible.
# 6  
Old 10-18-2012
I have already told you that, I am not able to find any relation between those two files.
And i think others too..Smilie

So its better to give some example which has relation between each other. So that it will be very helpful to understand.Please post your Input files(which are related to each other) and desired output.

It's not possible to give solution all the time by assuming everything.

Hope this helps you...Smilie
# 7  
Old 10-18-2012
Request to check

Hi

I have attached a small second file

and first file is like this

Code:
F2
CHRM1
TLS3
CPS3


Now I want to search entries in first file in the # Drug_Target_X_Gene_Name (X= 1-1000)heading (Mentioned on page 11 of second file as sample)

if it matched as here F2 is matching then it should fetch following entries

#description , #indication and # pharmacology from each Drug card

So output will be

Code:
F2   #description Lepirudin is identical to natural hirudin except for  substitution of leucine for isoleucine at the N-terminal end of the molecule and the absence of a sulfate group on the tyrosine at position 63. It is produced via yeast cells.

#indication   For the treatment of heparin-induced thrombocytopenia


# pharmacology Lepirudin is used to break up clots and to reduce thrombocytopenia. It binds to thrombin and prevents thrombus or clot formation. It is a highly potent, selective, and essentially irreversible inhibitor of thrombin and clot-bond thrombin. Lepirudin requires no cofactor for its anticoagulant action. Lepirudin is a recombinant form of hirudin, an endogenous anticoagulant found in medicinal leeches.


Note: Drug_Target_X_Gene_Name entries are present between drug cards and drug card starts with

#BEGIN_DRUGCARD DB0xxxx (0001- 8820)

#END_DRUGCARD DB0xxxx (0001- 8820)


Hope it helps

Previous Thread | Next Thread
Test Your Knowledge in Computers #242
Difficulty: Easy
In September 1984 work was completed on restructuring the ARPANET giving U.S. military sites their own Military Network (MILNET) for unclassified defense department communications.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to fetch specific data from a file.?

Hi , I have a file which contains 2 days logs(here it is 24 and 25) I want to list data only for date 25 fron the file. please suggest me how should i get this. file content mentioned below 17-05-24 Name Succ Fail 00:00:29 ... (5 Replies)
Discussion started by: scriptor
5 Replies

2. Shell Programming and Scripting

Search and replace specific positions of specific lines

Hi, I have a file with hundreds of lines. I want to search for particular lines starting with 4000, search and replace the 137-139 position characters; which will be '000', with '036'. Can all of this be done without opening a temp file and then moving that temp file to the original file name. ... (7 Replies)
Discussion started by: dsid
7 Replies

3. UNIX for Dummies Questions & Answers

Search specific string logfile specific date range

Hi, I have logfile like this.. === 2014-02-09 15:46:59,936 INFO RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header === 2015-02-09... (8 Replies)
Discussion started by: kishk
8 Replies

4. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

5. Shell Programming and Scripting

Fetch entries with specific pattern

Hi all, I have following sample input file which is a part of big file: ID AINX_HUMAN Reviewed; 499 AA. AC Q16352; B1AQK0; Q9BRC5; DT 30-MAY-2000, integrated into UniProtKB/Swiss-Prot. DT 23-JAN-2002, sequence version 2. DT 28-NOV-2012, entry version 123.... (2 Replies)
Discussion started by: kareena
2 Replies

6. Shell Programming and Scripting

Fetch specific entries

Hi Guys This time my input sample from a Big file like this In TTDS00002 UniProt ID P11229 TTDS00002 Name Muscarinic acetylcholine receptor M1 TTDS00002 Type of target Successful target TTDS00002 Synonyms M1 receptor TTDS00002 Disease Alzheimer's disease... (13 Replies)
Discussion started by: Priyanka Chopra
13 Replies

7. Shell Programming and Scripting

Urgent request to consider:Search specific name in a file and fetch specific entries

Hi all, I have 2 files, One file contain data like this FHIT CS CHRM1 PDE3A PDE3B HSP90AA1 PTK2 HTR1A ESR1 PARP1 PLA2G1B These names are mentioned in the second file(Please see attached second file) as # Drug_Target_X_Gene_Name:(Where X can be any number (1-1000) (1 Reply)
Discussion started by: manigrover
1 Replies

8. Shell Programming and Scripting

fetch last line no form file which is match with specific pattern by grep command

Hi i have a file which have a pattern like this Nov 10 session closed Nov 10 Nov 9 08:14:27 EST5EDT 2010 on tty . Nov 10 Oct 19 02:14:21 EST5EDT 2010 on pts/tk . Nov 10 afrtetryytr Nov 10 session closed Nov 10 Nov 10 03:21:04 EST5EDT 2010 Dec 8 Nov 10 05:03:02 EST5EDT 2010 ... (13 Replies)
Discussion started by: Himanshu_soni
13 Replies

9. Shell Programming and Scripting

How to fetch a specific line from file

Hi, I have text file in the following strucher . The files contain hondreds of lines. value1;value2;value3;value4 I would like to get back the line with lowest date (values4 field). In this case its line number 3. groupa;Listener;1;20110120162018 groupb;Database;0;20110201122641... (4 Replies)
Discussion started by: yoavbe
4 Replies

10. Shell Programming and Scripting

To fetch specific words from a file

Hi All, I have a file like this,(This is a sql output file) cat query_file 200000029 12345 10001 0.2 0 I want to fetch the values 200000029,10001,0.2 .I tried using the below code but i could get... (2 Replies)
Discussion started by: girish.raos
2 Replies

Featured Tech Videos