The UNIX and Linux Forums  


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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Yellow Book assistance needed FL1 UNIX for Dummies Questions & Answers 2 11-15-2007 04:04 PM
Script Needed Urgent in shell or PERL!!!!!!!!!!!!!!!!!!!! aajan Shell Programming and Scripting 1 10-24-2007 05:28 AM
Perl script assistance; paste word into external command bru Shell Programming and Scripting 10 02-23-2007 04:04 AM
Assistance needed. 12yearold UNIX for Dummies Questions & Answers 4 07-07-2006 04:26 AM
NFS mount assistance needed... Heron UNIX for Dummies Questions & Answers 2 03-21-2005 04:31 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2009
SkySmart SkySmart is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 50
Assistance needed with perl script

Ok, theres a log file containing the below. Lets call the logfile log_fantastic:

2009/03/16 21:42:45 USER: tonnabo - MAC: 0014BF2D385A - STATUS_ID: 30 - STATE: ERROR
2009/03/16 21:42:45 USER: tonnabo - MAC: 001310AC120D - STATUS_ID: 15 - STATE: OK
2009/03/16 21:42:45 USER: tonnabo - MAC: 001DD9277095 - STATUS_ID: 20 - STATE: ERROR


I want to write a perl script that will read the contents of log_fantastic and output only the lines that does not have a status_id of 10?

the below is what i've done. not sure if this is correct:


use Data:: Dumper;

main();


sub main {
my @results;
my $headers = "user,
mac address,
status_id";

my (@log_info, @dircontents);


open (LOG, "</home/jhenson/log_fantastic");
@log_info = <LOG>;
close (LOG);

print Dumper("testing");
foreach my $content (@log_info) {
chomp($content);
my $line = substr ($content, -2);
print Dumper($line);
if ($line eq "OK") {
push @dircontents, $content;
}
}


#push @alarm_info, uc $headers;

print Dumper(@dircontents);

}
  #2 (permalink)  
Old 03-17-2009
curleb curleb is online now
Registered User
  
 

Join Date: Mar 2008
Location: Here, in my Ivory Tower...
Posts: 68
you need a perl script to do this? :


Code:
grep -v 'STATUS_ID: 10 ' ${file:-"/home/jhenson/log_fantastic"}

Or is there more to it...?
  #3 (permalink)  
Old 03-17-2009
SkySmart SkySmart is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 50
Quote:
Originally Posted by curleb View Post
you need a perl script to do this? :


Code:
grep -v 'STATUS_ID: 10 ' ${file:-"/home/jhenson/log_fantastic"}

Or is there more to it...?


oh theres more to it. i coulda easily done this through shell programming. but this needs to be done in perl. on top of grepping out the wanted status ids, i goto set it up in fields. thanks a million for your suggestion
  #4 (permalink)  
Old 03-17-2009
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 137
Try the perl script : -
==================

#!/usr/bin/perl
open(FH,"log_fantastic") or dir ("Couldnt open file");
while(<FH>)
{
$rec=$_;
chomp ($rec);
@arr=split(/:/,$rec);
print $rec,"\n" if ($arr[5]!~/10/);
}
close(FH);
  #5 (permalink)  
Old 03-17-2009
SkySmart SkySmart is offline
Registered User
  
 

Join Date: Dec 2006
Posts: 50
Quote:
Originally Posted by jambesh View Post
Try the perl script : -
==================

#!/usr/bin/perl
open(FH,"log_fantastic") or dir ("Couldnt open file");
while(<FH>)
{
$rec=$_;
chomp ($rec);
@arr=split(/:/,$rec);
print $rec,"\n" if ($arr[5]!~/10/);
}
close(FH);


this works PERFECTLY. thanks a million.
  #6 (permalink)  
Old 03-17-2009
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
This should be more efficient and more accurate:


Code:
open(FH,"log_fantastic") or dir ("Couldnt open file: $!");
while(my $line = <FH>) {
   next if (/STATUS_ID: 10 /);
   print;
}
close(FH);

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0