The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 03-18-2009
SkySmart SkySmart is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 48
Quote:
Originally Posted by pludi View Post
Code:
#!/usr/local/bin/perl

open (MYFILE, 'logs_report');
open (MYF, '>data.txt');

while ($rec = <MYFILE>) {
    chomp($rec);
    @arr = split(/ /,$rec);
    if ($arr[12] !~ /OK/) {
        print $rec, "\n";
        print MYF $red, "\n";
    }
}
close (MYF);
close (MYFILE);
This is probably what you want. The way you wrote it, you'd overwrite your data.txt every time you find something, plus opening and closing repeatedly in a loop can be quite I/O cost intensive.

And the next time you post listings or source, enclose it in [ code][/code ] tags (sans the spaces), to preserve formatting for readability.

thank you. sorry for not including the codes. would you happen to know how to include a code in ur code that will email the file to a set of email addresses? i mean the file that is written to? your help or input is greatly appreciated. thanks