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
Perl Pattern Matching !!! Help maxmave Shell Programming and Scripting 0 06-03-2008 08:05 PM
perl pattern matching zedex Shell Programming and Scripting 2 09-30-2007 09:29 AM
Perl: Pattern Matching a HASH variable pondlife Shell Programming and Scripting 1 04-10-2006 04:31 PM
perl pattern matching vs. grep junkmail426 Shell Programming and Scripting 0 09-28-2005 11:40 AM
pattern matching + perl question Optimus_P Shell Programming and Scripting 1 12-05-2003 07:43 PM

 
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
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-14-2008
ganapati's Avatar
ganapati ganapati is offline
Registered User
  
 

Join Date: Jul 2006
Location: Mysore
Posts: 125
Exclamation Pattern matching problem in PERL script

Hi Friends,

As my old friends knows, I'm old to shell script but very new to perl script, currently I'm writing
a PERL script with the following functionality:

I've multiple product directories, like BUSS, FIN, SALES, MKT etc., :
/export/home/GLK/BUSS,
/export/home/GLK/FIN,
/export/home/GLK/SALES,
/export/home/GLK/MKT
etc..,

Above all directories will have one report file with the same name 'missing_party.rpt'.

This report file contains a lot of information, out of which I need to extract
only the lines which has the pattern "My dear boss(.....some info...) Thanks".

I've to redirect only the above pattern line into a output file "/export/home/OUTPUT/output.txt"
by discarding the remaining line.

I've written the below script, with the help of google

#!/usr/bin/perl

use File::Find;
use strict;

my $directory = "/export/home/GLK";
my $out_filename = "/export/home/GLK/output.txt";

find (\&process, $directory);

sub process
{
my @outLines; #Data we are going to output
my $line; #Data we are reading line by line

# Only parse files that end in .html
if ( $File::Find::name =~ /\missing_party.rpt$/ ) {
open (FILE, $File::Find::name ) or die "Cannot open file: $!";
open( OUTFILE, "> " . $out_filename ) or die "Cannot open file: $!";

# print "\n" . $File::Find::name . "\n";
while ( $line = <FILE> ) {
$line =~ m/"My dear boss(.....some info...) Thanks"/ ;
push(@outLines, $line);
print ( OUTFILE @outLines );
}
close FILE;
close ( OUTFILE );
undef ( @outLines );
}
}


The problem with the above script is, I need to extract only the information "My dear boss(.....some info...) Thanks" from the entire line. But current code is extracting complete line.
I dont know how to implement it.....

Could any one help me ... also is it possible to fine tune the above code...? Even though I'm new, requirement is for the optimal code.

Thanks in advance... / Mysore Ganapati.

Last edited by ganapati; 10-14-2008 at 11:23 AM.. Reason: to correct the mistake
 

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 02:18 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