Perl program for find one entry and put in different file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl program for find one entry and put in different file
# 1  
Old 05-04-2012
just execute the below line in the command line.

Dont put it in your perl file

Code:
 
cat TTDtargets | perl -n -e 'chomp; if(m/^\s*(\D+)\s*(\d+)\s+Uniprot ID\s+(\d+)/){printf("%s for %s %s\n",$3,$1,$2)}'> TTD2

# 2  
Old 05-04-2012
Thanks Kamraj

But this time it gave me the file TTD2 but its completely blank

is there somethign wrong with out put command

my input file contains

TTDS00001 Antagonist GSK233705 DCL000823
TTDS00001 Antagonist NVA237 DCL000901
TTDS00001 Antagonist Org-23366 DCL000911
TTDS00001 Antagonist OrM3 DCL000913
TTDS00001 Multitarget Org-23366 DCL000911
TTDS00001 Antagonist Aprophen DNC000245
TTDS00001 Antagonist Benactyzine DNC000293
TTDS00001 Antagonist Hyoscine DNC000757
TTDS00001 Antagonist Hyoscyamine sulfate DNC000758
TTDS00001 Antagonist Ipratropium bromide DNC000806
TTDS00001 Agonist Muscarine DNC000970
TTDS00001 Agonist RS 86 DNC001236
TTDS00001 Target Validation TTDS00001
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
TTDS00002 Disease Bronchospasm (histamine induced)
TTDS00002 Disease Cognitive deficits
TTDS00002 Disease Schizophrenia
TTDS00002 Function The muscarinic acetylcholine receptor mediates various cellular responses, including inhibition of adenylate cyclase.................. so on for TTD 03/04/..14447

I have to capture only Uniprot ID and put in Output
# 3  
Old 05-04-2012
so, as per the above input, the expected output is P11229 ?

Please use [code] tag while posting the data and command

https://www.unix.com/how-post-unix-li...code-tags.html

---------- Post updated at 12:15 PM ---------- Previous update was at 12:14 PM ----------

Try this.

Code:
 
$ perl -lane 'print $F[-1] if $_=~/UniProt ID/' TTDtargets
P11229

# 4  
Old 05-04-2012
Thank for reply.My Input contains many Uniprot entries like one Uniprot ID which I mentioned in one part of so file conatin 1400 approx Uniprot entries..

Code:

Method 1:

cat TTD Targets | perl -n -e 'chomp; if(m/^\s*(\D+)\s*(\d+)\s+Uniprot ID\s+(\d+)/){printf("%s for %s %s\n",$3,$1,$2)}'> TTD2;

Error:Blank TTD2 file I m receiving

Method 2:$ perl -lane 'print $F[-1] if $_=~/UniProt ID/' TTDtargets


Error:command not found
# 5  
Old 05-04-2012
can you post your code with code tag

otherwise, i cant help. sorry

https://www.unix.com/how-post-unix-li...code-tags.html

post the entire error message and the command what you tried.
# 6  
Old 05-04-2012
Method 1:

bash-3.2$ $ perl -lane 'print $F[-1] if $_=~/UniProt ID/' TTDtargets
bash: $: command not found

Method2:

bash-3.2$ cat Uniprot | perl -n -e 'chomp; if(m/^\s*(\D+)\s*(\d+)\s+Uniprot ID\s+(\d+)/){printf("%s for %s %s\n",$3,$1,$2)}'> TTD2
# 7  
Old 05-04-2012
why the $ before the perl ?

Code:
 
bash-3.2$ $ 

still you are not posting with [code] tag

you will be banned if you not take this as serious. (So no more help from this forum )


(B) Use [code] tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
Code:
 and

by hand.)


Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

How to find a garbage entry in a column wise text file in Linux?

Suppose I have a file containing :- 1 Apple $50 2 Orange $30 3 Banana $10 4 Guava $25 5 Pine@apple $12 6 Strawberry $21 7 Grapes $12 In the 5th row, @ character inserted. I want through sort command or by any other way this row should either on top or bottom. By sort command garbage... (1 Reply)
Discussion started by: Dipankar Mitra
1 Replies

2. Shell Programming and Scripting

remove brackets and put it in a column and remove repeated entry

Hi all, I want to remove the remove bracket sign ( ) and put in the separate column I also want to remove the repeated entry like in first row in below input (PA156) is repeated ESR1 (PA156) leflunomide (PA450192) (PA156) leflunomide (PA450192) CHST3 (PA26503) docetaxel... (2 Replies)
Discussion started by: manigrover
2 Replies

3. UNIX for Dummies Questions & Answers

Statement to find if an entry exists in a file

I need to check if an entry input by the user is in a file. If so, I need to run a command, and if it does not exist then it should output entry does not exist. So I have so far... echo "Enter record:" read record //command || //command Can I use an if statement to do this? (3 Replies)
Discussion started by: itech4814
3 Replies

4. Shell Programming and Scripting

How to find the matched numbers between 2 text file using perl program??

hi dudes, I nee you kind assistance, I have to find the matched numbers from 2 text files and output of matched numbers should be in another text file.. I do have text files like this , for example File 1 787 665*5-p 5454 545-p 445-p 5454*-p File 2 5455 787 445-p 4356 2445 144 ... (3 Replies)
Discussion started by: sureshraj
3 Replies

5. Shell Programming and Scripting

Find similar entry in a .txt file acting as a database.

May i know how do i go along finding similar entry in a .txt file, which is used a as a "database" and post and error saying the entry existed when we key in the entry. ---------- Post updated at 05:18 PM ---------- Previous update was at 05:16 PM ---------- i mean post an error saying the... (5 Replies)
Discussion started by: santonio
5 Replies

6. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

7. Shell Programming and Scripting

find function name in a program file

Hello All, Is there any way to find a function name in a program file using perl. for example, there is a file called Test.C in that . . void function1(..) { <some code> } int function2(..) { . . sam() /*RA abc100*/ ... .. .. xyz()/*RA abc201*/ .. (8 Replies)
Discussion started by: Parthiban
8 Replies

8. UNIX for Dummies Questions & Answers

Program to find palindrome from a file

hello i came up with this ..The problematic part that i am facing is in underline and bold format. exec<file while read line do set $line i=1 while do str=$i #problematic i want the positional parameter but here it takes integer value. p=1 q=`expr length $str` flag=1... (6 Replies)
Discussion started by: salman4u
6 Replies

9. Shell Programming and Scripting

Perl find::file can I sort the out put

Perl file::find can I sort the out put I am using file::find in my script but how I wish to process each file found in date order. Can I sort this module? eg part of current script is.... use File::Find; # Recursively find all files and directories in $mqueue_directory find(\&wanted,... (2 Replies)
Discussion started by: Andrek
2 Replies

10. Shell Programming and Scripting

Adding entry into crontab in ksh program

Hi falks, I have the following ksh function ,which adding entry to crontab during ksh program running: { print "Go\c" >/dev/null 2>&1 print '0 0 * * * su - ias -c "/home/orca/core-${SCHEMA_NAME}/CLI/cleanup_BRMS.ksh"\c' >/dev/null 2>&1 print "\033:wq!" >/dev/null 2>&1 } | \crontab -e... (2 Replies)
Discussion started by: nir_s
2 Replies
Login or Register to Ask a Question