Help starting a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help starting a script
# 1  
Old 03-01-2012
Question Help starting a script

Hi guys, i already search in this forum and i can't find a way to do this. I have a file like this:
Code:
-1    1    lig
-1    1    lig
-1    1    lig
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec

And i need to compare the values of columns $1 and $2 and get a output with the results of diferences combinations, for exemple if $1=1 and $2=1 output TP, if $1=1 and $2=-1 output FP if $1=-1 and $2=1 output FN

The point is to count compare colum $1 that is a results from other script with colum $2 that is reall results and see if it is true positives, false negatives and false positives.

I already seach and im thinking using AWK with IF, but i don't know how to tell in the IF part of the script that

Code:
 if $1==1 $2==1 print TP for output.

Any ideas are wellcome thanks Smilie
# 2  
Old 03-01-2012
And if you have $1==-1 and $2==-1?
# 3  
Old 03-01-2012
Code:
#!/usr/bin/perl -w                                                                                                                    
                                                                                                                                      
@a=qw(0 0 0 0);                                                                                                                       
while(<>){                                                                                                                            
    /^(.+?)\s+(.+?)\s+/;                                                                                                              
    $a[0]++,next if($1 == 1 && $2 == 1);                                                                                              
    $a[1]++,next if($1 == 1 && $2 == -1);                                                                                             
    $a[2]++,next if($1 == -1 && $2 == 1);                                                                                             
    $a[3]++,next if($1 == -1 && $2 == -1);                                                                                            
}                                                                                                                                     
                                                                                                                                      
print"$a[0]     $a[1]   $a[2]   $a[3]\n";

syntax: ./script filename
This User Gave Thanks to For This Post:
tip78
# 4  
Old 03-01-2012
Quote:
Originally Posted by bartus11
And if you have $1==-1 and $2==-1?
Because i only need to count the number of the these ocorrences for caculate the precision and recall of my data Smilie

Code:
#!/usr/bin/perl -w                                                                                                                    
                                                                                                                                      
@a=qw(0 0 0 0);                                                                                                                       
while(<>){                                                                                                                            
    /^(.+?)\s+(.+?)\s+/;                                                                                                              
    $a[0]++,next if($1 == 1 && $2 == 1);                                                                                              
    $a[1]++,next if($1 == 1 && $2 == -1);                                                                                             
    $a[2]++,next if($1 == -1 && $2 == 1);                                                                                             
    $a[3]++,next if($1 == -1 && $2 == -1);                                                                                            
}                                                                                                                                     
                                                                                                                                      
print"$a[0]     $a[1]   $a[2]   $a[3]\n";

I was trying to do this in bash with awk because the rest of my scripts is in bash (im from Biology and im very new with bash and is the 1st linguage that im learning and i don't know how to use more)

Thanks for the fast reply
# 5  
Old 03-01-2012
Please post what the matching output from the 9 lines in the sample input in post #1 should look like.
# 6  
Old 03-01-2012
Quote:
Originally Posted by methyl
Please post what the matching output from the 9 lines in the sample input in post #1 should look like.
The aim is to count the number of occurences:
Code:
-1    1    lig -> this is a FN
-1    1    lig -> this is a FN
-1    1    lig -> this is a FN
-1    -1    dec 
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec

So im trying to print something like this "FN=3 TP=0 TN=0" because when $1=-1 and $2=-1 i don't need to count

Last edited by MetaBolic0; 03-02-2012 at 07:11 AM..
# 7  
Old 03-01-2012
Quote:
So im trying to print something like this "FP=3 TP=0 TN=0" because when $1=-1 and $2=-1 i don't need to count
Maybe I'm being thick but I repeat:
Please post what the matching output from the 9 lines in the sample input in post #1 should look like.

Last edited by methyl; 03-01-2012 at 09:17 PM.. Reason: various
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

2. Shell Programming and Scripting

Script for Starting Firefox?

Presently I have a powershell script (windows only, of course) that enumerates all the instances of "Internet Explorer" running on my machine and if at least one exists, the script creates a new tab in that instance with the URL I have provided. If no instances of Internet Explorer are running, one... (1 Reply)
Discussion started by: siegfried
1 Replies

3. Shell Programming and Scripting

Starting all the components simultaneously through script

Hi Folks , I have the below script that will start the components one by one by giving an interval of few seconds that if first component is started then there is interval of few seconds and then the second component is started , but by this way it takes time, i want to make the process faster... (8 Replies)
Discussion started by: punpun66
8 Replies

4. Shell Programming and Scripting

Help with Temperature Script (Starting

Hello, I am trying to work on a temperature script to check temperatures on my systems. Im trying to get the basics laid out first. So far i have a command: /usr/sbin/prtpicl -v -c temperature-sensor # (must run as root) This command kicks back alot of information but i only want the... (3 Replies)
Discussion started by: whotippedmycow
3 Replies

5. Shell Programming and Scripting

Starting a C++ program from shell script

Hi, I have a little problem...I want to do the following things: Have my own little script that has 2/3 functions and starts a c++ application using some parameters. The problems appear when I start the c++ app using the shell script, the c++ takes over and after I ctrl+c the script... (0 Replies)
Discussion started by: valiadi
0 Replies

6. Shell Programming and Scripting

Starting script without ./ name or sh name

Hi, i want to start my script only by the name of it. $ scriptName normaly i have to use ./scriptName oder sh scriptName is there a way to do that in bash or sh ? (13 Replies)
Discussion started by: Turrican
13 Replies

7. Shell Programming and Scripting

Manage starting point in shell script.

Hi, I'd like to run a script with an optional starting point. Meaning that if no parameter for the script => Do everything, otherwise start from the point specified in the parameter and continue till the end. I thought of using the "case ..." but I have no result. Script: # ---------------... (6 Replies)
Discussion started by: ai_dba
6 Replies

8. UNIX for Dummies Questions & Answers

Problem starting a script from a 'main'-script

Please Help! :o I have a main script (ksh) where another script is called (convert_picture). Normally this works ok, but since some changes has been made on the unix-server (I dont know what :( ) suddenly it doesnt work anymore: i get an error message: ksh: convert_picture not found. I am... (3 Replies)
Discussion started by: Rakker
3 Replies

9. Shell Programming and Scripting

Help starting a simple shell script.

I've been sitting here for 6 hours typing out all kinds of different ridiculous(very pointless) shell scripts for a low-level UNIX class. I'm tired.. and want to go to bed :o Can somebody please help get me on the right path to starting this damn script? i'm useless after all these hours and... (2 Replies)
Discussion started by: dickmartin
2 Replies

10. UNIX for Advanced & Expert Users

Starting a script from a Database procedure

Hey guys, I have this problem : I can run on an sqlprompt !ftp_file2.ksh test.xml 172.16.204.81 Anonymous Anonymous which will ftp the file from Unix to an NT machine, but if I do exec shell('sh ftp_file2.ksh test.xml 172.16.204.81 Anonymous Anonymous') it does NOTHING. I have no... (4 Replies)
Discussion started by: vidireporting
4 Replies
Login or Register to Ask a Question