O Monks-
I'm writing a program that searches pushes a set of text files into an array, then searches through each file of the array for keyword matches. The way I have the program written now, I pull the text match and the text around it and push it to an outfile, then move on to the next file. Now, instead of pushing the text match to an output file, I only want to create one excel spreadsheet with two columns: one with the file name and one that can take on values of Y or N, depending on whether or not the file contains the keyword match.
Here's the code:
foreach $list (@list) { if ($list =~ m/\/if\/home\/m1hrb00\/covenants\/Contracts\/(.*)\.tx +t/) { #select the index of contract names, trim off the filepath push (@contract_list, $1); print STDERR "$1 \n"; } } $beforecount = 10; + #set how many lines before the match you'd like to pull; $aftercount = 10; + #set how many lines after the match you'd like to pull; foreach (@contract_list) { + #pull in the array of contracts open Contract1, "<./$_.txt \n"; @lines = <Contract1>; close Contract1; my $contents = join "", @lines; @all = undef; shift @all; #loop for Governance + + $infile = "$_"; my $incontract = "$infile".".txt"; print STDERR "$incontract read \n"; while ($contents =~ m/Governance/i) { if ($contents =~ m/((\n.*){$beforecount}Governance(.*\n){$aftercou +nt})/i) { push (@all, "$1\n"); print STDERR "$1\n"; $contents =~ s/Governance//i; $contract = "$_"; my $outfile = "$contract".".txt"; open (Contract1a, ">", "/if/home/m1hrb00/covenants/CorporateGo +vernance/Governance/$outfile") || die("Cannot open output file $outfile: $!"); print Contract1a join("\n", (@all)); print STDERR "$outfile matched \n"; close Contract1a;
I want to add at the end another line to do what I mentioned above. Thanks!
In reply to Writing to an Excel file by NorthShore44
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |