NorthShore44 has asked for the wisdom of the Perl Monks concerning the following question:
#! /opt/local/bin/perl -w # Part 1: Write all of the filenames to Index.txt to be able to inpu +t names as an array # open directory1, ">./index.txt" or die "Could not create file: $!\n"; use File::Find; my @all_file_names; find sub { return if -d; push @all_file_names, $File::Find::name; }, '*my directory*'; for my $path ( @all_file_names ) { select directory1; print "$path\n"; } print STDERR "contents of directory written \n"; close directory1; ################################################## # Part 2: Open & Read Contract List + # ################################################## my $filename = 'index.txt'; open my $fh, $filename or die "Couldn't read '$filename': $!"; #chomp @ARGV = <$fh>; print "Processing $_" for @ARGV; ################################################## # Part 3: Read in the contracts and search for keywords + # ################################################## open Contract1a, ">./test.txt" or die "Could not create file: $!\n"; @contracts = @ARGV; $linescount = 20; #set how many lines after the match you'd like t +o pull; foreach (@contracts) { open Contract1, "<./$_ \n"; @lines = <Contract1>; close Contract1; my $contents = join "", @lines; @all = undef; shift @all; while ($contents =~ m/Management Fees/i) { if ($contents =~ m/(\n.*Management Fees(.*\n){$linescount})/i) { push (@all, "$1\n"); print STDERR "$1\n"; $contents =~ s/Management Fees//i; } } select Contract1a; print join("\n",(@all)); print "\n"; } print STDERR "...Contract1 match complete.\n\n"; close Contract1a;>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading a Directory of Files, Searching for Text, Outputting Matches
by cdarke (Prior) on Oct 13, 2009 at 16:07 UTC | |
|
Re: Reading a Directory of Files, Searching for Text, Outputting Matches
by gmargo (Hermit) on Oct 13, 2009 at 17:31 UTC | |
|
Re: Reading a Directory of Files, Searching for Text, Outputting Matches
by planetscape (Chancellor) on Oct 13, 2009 at 22:35 UTC | |
|
Re: Reading a Directory of Files, Searching for Text, Outputting Matches
by stonecolddevin (Parson) on Oct 13, 2009 at 20:58 UTC | |
|
Re: Reading a Directory of Files, Searching for Text, Outputting Matches
by afoken (Chancellor) on Oct 13, 2009 at 20:55 UTC |