Perl: Search for string on line then compare numbers!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: Search for string on line then compare numbers!
# 1  
Old 01-21-2008
Perl: Search for string on line then compare numbers!

Hi All,

I have a file that I need to be able to find a pattern match on a line, take the number on that line check if its >0.9 or <0.1 and if this is true write the line to output.out file.

An example of 4 lines in my file is:

1. driver.I177.I11.net010 1.48622200477273e-05
2. driver.I177.I11.net018 0.999979181369536
3. driver.I177.I11.net019 0.699980513717918
4. driver.I177.I11.net23 1.05599228036606e-05
5. vsub 2.42896969967089e-05

The above is an example of four lines. I want to find all the lines containing "driver" (lines 1,2,3 and 3) check if the numbers meet 0.1<x<0.9 and write the lines that match to a output file (line 3).

Hope that makes sense!!
Many thanks
# 2  
Old 01-22-2008
try this script:
Code:
#!/usr/bin/perl
# driver_nums.pl
while (<>) {
    if (m/driver(.*?) (.*)$/) {
        print  if (0.1 < $2  and  $2 < 0.9);
    }
}

run it as:
Code:
perl driver_nums.pl driverfile > newfile

# 3  
Old 01-22-2008
Code:
awk '/driver/ && $NF<0.9 && $NF > 0.6' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to compare numbers in alphanumeric string

Hi, I will be having file names like below, 1420SP1.01804 1420SP1.01805D 1420SP1.01805 1420SP1.01806D 1420SP1.01806 1420SP1.01901D 1420SP1.01901 1420SP1.01902D 1420SP1.01902 1420SP1.01903D 1420SP1.01903 1420SP1.01904 1420SP1.01905 From this, I need to list file names which is... (3 Replies)
Discussion started by: Sumanthsv
3 Replies

2. Shell Programming and Scripting

Search every line and compare fields

Hi All, I have situation where my file looks like this log.file. ID Start time IP SQL 1256152 05-Aug-15, 11:25:06 MST 10.54.20.33 Select * from TES 1004768 05-Aug-15, 11:25:06 MST 10.54.20.33 Select dummy 323323 05-Aug-15, 12:00:06 MST 10.15.20.77 ... (1 Reply)
Discussion started by: netdbaind
1 Replies

3. UNIX for Dummies Questions & Answers

Search for string in a file then compare it with excel files entry

All, i have a file text.log: cover6 cover3 cover2 cover4 other file is abc.log as : 0 0 1 0 Then I have a excel file result.xls that contains: Name Path Pass cover2 cover3 cover6 cover4 (1 Reply)
Discussion started by: Anamika08
1 Replies

4. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

5. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

6. Shell Programming and Scripting

Truncate all characters and numbers in string - using perl

hi, I have an data from file where it has 20110904 234516 <<hdd-10#console|0c.57,passed,5,28,READ,0,20822392,8,5,4,0,40,0,-1,0,29909,25000,835,3.3,0,0,0,0,implied,0,0,2011/9/5-2:3:17,2011/9/5-2:3:47,X292_0F15,TAP ,NQ09,J40LTG\r\r\n I want to remove characters till #console| i.e want... (1 Reply)
Discussion started by: asak
1 Replies

7. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

9. UNIX for Advanced & Expert Users

perl: string comparison as numbers

$name = 'Mark'; $goodguy = 'Tody'; if ($name == $goodguy) { print "Hello, Sir.\n"; } else { print "Begone, evil peon!\n"; } The output is Hello, Sir...... Even if the Mark is made to MarkSpencer.....then also it shows as Hello, Sir.... Can any one explain the... (7 Replies)
Discussion started by: bishweshwar
7 Replies

10. Shell Programming and Scripting

Perl: Search for string then parse next line

Hi All, I have a file that I need to be able to find a pattern match on one line then parse data on the next or subsequent lines - I will know which line needs to be parsed beforehand. This is what I currently have: while (<COMMAND_OUT>) { if ($_ =~ m/TEST/) { ... (4 Replies)
Discussion started by: pondlife
4 Replies
Login or Register to Ask a Question