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-03-2012
Lightbulb Perl program for find one entry and put in different file

Hi

I have a file

name1 xxxxx
name1 xxxxx
name1 yyyyy
name 1 zzzzz
name1 Uniprot Id 1234
name2 sssss
name2 eeeee
name2 bengamine
name2 Uniprot Id 3456
......................and so on

I have to capture Uniprot IDs only in a separate file so that output contain only

Uniprot ID for name 1
Uniprot ID for name 2............... and so on

Can any body help to write a perl programm for this.

My another questions is regarding compare 2 files:

one file
Uniprot ID 1(any number)
Unipro ID 6
Unirot ID 7
.......so on randomly
another file contains

Uniprot ID1
Uniprot ID2
Uniprot ID 6
Uniprot ID8
..so on

I have to compare 2 files to find which and hw many entries are and common in both files and if these are common than print before entry common other wise not common.

Please let me know Perl programm for these question... highly thankful fo r somebody..indeed

Thanks
Mani
# 2  
Old 05-03-2012
Possibly something like this:
Code:
cat yourfile | perl -n -e 'chomp; if(m/^\s*(\D+)\s*(\d+)\s+Uniprot Id\s+(\d+)/){printf("%s for %s %s\n",$3,$1,$2)}' > outfile

# 3  
Old 05-04-2012
Request to check

Thanks for the reply. I m receiving followin error:

Unquoted string "perl" may clash with future reserved word at test.pl line 3.
syntax error at test.pl line 3, near "n -e"
Execution of test.pl aborted due to compilation errors.

can anybody guide.
# 4  
Old 05-04-2012
Are you using windows ?

when you are asking the question, mention the OS and shell
# 5  
Old 05-04-2012
Request to check

Hi Kamraj

I am using Unix OS with Unix shell
# 6  
Old 05-04-2012
can you post your command
# 7  
Old 05-04-2012
Hi

My programm is in a file named test.pl


#!/usr/bin/perl -w

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;

END


my command and error is :



bash-3.2$ perl test.pl
Unquoted string "perl" may clash with future reserved word at test.pl line 3.
syntax error at test.pl line 3, near "n-e "
Execution of test.pl aborted due to compilation errors.

---------- Post updated at 01:20 AM ---------- Previous update was at 01:19 AM ----------

Here input file name is TTD Targets and outut file name is TTD2
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