the same script, the final step, and again does not do what I wnat it to do
Hello all, Thanks to Charles and Tim, I have advanced to the final step with my script. After the script verifies that there is line (Summary Log...) and that the log is from correct year and month. I want it to find a line where is " Impressions: XX" and retrieve that value. However I got 0 (zero) as an result, even tough I know that there are values (Impressions). The script now looks like: #!usr/bin/perl -w use strict; use Fcntl qw[:flock]; my $impressions = 0; my $iofile = '/other/XPSmaint/scripts/billing/daniel/input/c07_impressions_io.info'; open (IO, $iofile) || die("Could not open file 1!"); while ( ) { chop; my ($FH, $output, $file2check, $month, $year) = split (/\s+/, $_); open OUT, ">> $output"; chdir $FH or die "$!"; while (glob $file2check) { open FH, $_ or die $!; flock FH, LOCK_SH or die $!; while ( ) { chomp; if ( / Summary Log \(generated:/ ) { my($emptyspce, $summary, $log, $generated, $day_word, $monthfile, $day_number, $time, $timezone, $yearfile ) = split(/\s+/, $_); #print "File $file2check is $monthfile, $year\n"; if ($monthfile eq $month and $yearfile eq $year){ #print "File has this year: $yearfile and month: $monthfile in it.\n"} if ( /Impressions:/ ) { my($text, $value) = split(/:/, $_); $impressions += $value if ($value =~ /\d+/); } } } } close FH or die $!; } print OUT 'Total impressions: ', $impressions or die $!; } Any suggestions? Thank you for your time. danield -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
how to construct 2 consecutive if conditions?
Hello all, I do have file where is: Summary Log (generated: Tue Apr 1 22:02:29 MST 2003) And I do have a script which goes through this file line by line. The first 'if' condition checks whether I have found the line I am interested in (Summary log...) The second 'if' then should check whether the month is "Apr" and the year is "2003". The script as it is now is not correct, since it evaluates the first condition and splits line into variables and then skips the second if. The script looks like: #!usr/bin/perl -w use strict; use Fcntl qw[:flock]; my $impressions = 0; my $iofile = '/other/scripts/daniel/input/c07_impressions_io.info'; open (IO, $iofile) || die("Could not open file 1!"); while ( ) { chop; (my$FH, my$output, my$file2check, my$month, my$year) = split (/\s+/, $_); #open OUT, ">> $output"; chdir $FH or die "$!"; while (glob $file2check) { open FH, $_ or die $!; flock FH, LOCK_SH or die $!; while ( ) { chomp; if ( / Summary Log \(generated:/ ) { (my$emptyspce, my$summary, my$log, my$generated, my$day_word, my$monthfile, my$day_number, my$time, my$timezone, my$yearfile ) = split(/\s+/, $_); #print "File $file2check is $monthfile, $year\n"; if ($monthfile eq $month and $yearfile eq $year){ print "File has this year: $yearfile and month: $monthfile in it.\n"} } } close FH or die $!; } # print OUT 'Total impressions: ', $impressions or die $!; } Thank you for your time. danield -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Why is this not a match?
Hello All, I am unable to find out why is this not matching: I do have a file where the second line contains: Summary Log (generated: Tue Apr 1 22:02:29 MST 2003) I am processing this file by this script: #!usr/bin/perl -w use strict; use Fcntl qw[:flock]; my $impressions = 0; my $iofile = '/other/scripts/daniel/input/c07_impressions_io.info'; open (IO, $iofile) || die("Could not open file 1!"); while ( ) { chop; (my$FH, my$output, my$file2check, my$month, my$year) = split (/\s+/, $_); open OUT, ">> $output"; chdir $FH or die "$!"; while (glob $file2check) { print "Processing $file2check"; open FH, $_ or die $!; flock FH, LOCK_SH or die $!; while ( ) { chomp; if ( / Summary Log (generated:/ ) { my($summary, $log, $generated, $day_word, $m, $day_number,$time,$timezone, $year ) = split(/\s+/, $_); # $impressions += $value if ($value =~ /\d+/); print "File $file2check is $month, $year\n"; } } close FH or die $!; } } # print OUT 'Total impressions: ', $impressions or die $!; print $output, $file2check, $month, $year Where I am checking if there is a line Summary log by "if ( / Summary Log (generated:/ ) {" And I am receiving this error: Unmatched ( in regex; marked by <-- HERE in m/ Summary Log ( <-- HERE genereated:/ at c07_imp.pl line 25. Does anybody know why? Thank you for your time. danield -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Calculations with date
Hello all, I am looking for an advice or suggestion in this task: I do have a Perl script which contains 2 variables ($low, $high). The value assigned to them depends on which day am I running that Perl script. Moreover, the variable $low has always be the first day of the previous month and similarly the variable $high the last day of the previous month. For instance: If I run this script today (2004, January 18), the low should be (18 days of current month + total days of previous month (2003, December (31)))= 49. The $high would get (how many days ago was the last day of the previous month) = 18. $low = 49 $high = 18 I am doing this calculations manually before I run the script. I would like to have this value determined and substituted inside the script. In addition the script should know how much day each month has and also correctly recognize when the month February has 28 and when 29 days and so on... I would appreciate any suggestions or examples. Thank you for your time. danield -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
How to count the size of files in a directory
Hello all, I do have a beautiful script, that counts a size of specified files ("ABAA.txt", "ABAC.txt") in a directory test. I have got this script from discussion board. Here is the script: my $dir='c:\\test'; my @files2check = ("ABAA.txt", "ABAC.txt"); my $totalSize= 0; foreach (@files2check) { $totalSize += (-s "$dir\\$_"); } print $totalSize; I would like to modify it that it will count the size of all files in the directory, EXCEPT those in list or so it will count the size of files that match first 2 characters "AB" (sort of AB*) Can anybody advice? Thank you for your time. danield -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
RE: Reading a log file, again = works as desired
Hello Tom, Thank you very much. I appreciate your help. This script works flawlessly, and does exactly what I need. Thank you for your time. danield >From: "Tom Kinzer" <[EMAIL PROTECTED]> >To: "Beginners Perl" <[EMAIL PROTECTED]> >Subject: RE: Reading a log file, again >Date: Mon, 8 Dec 2003 12:32:51 -0800 > >Try this: > >Caveat: This all assumes LOTS about the format of your data being >consistent, and so should be treated as a "quick and dirty" as opposed to >anything resembling a robust application... I'm not sure what your >intention with the script is, but is worth mentioning. > >-Tom Kinzer > >__SNIP__ > >my $input = '/appl/log/200301130.txt'; >my $total; >die "Usage: Arg1: Input File to Scan." > unless $input; > >open IN, "< $input" or die "Unable to open $input for reading, $!, stopped"; > > >while ( ) { > if ( / Document Format/ ) { last }; >} > >while ( ) { > if ( / Total: -/ ) { last }; >} > >while ( ) { > if ( /^\s*\d+/ ) { > chomp; > s/\s*(\d+)\s*/$1/; > $total = $_; > printf "Total: %010s\n", $total; > last; > } >} > >close IN; > >__END__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Reading from a log - still a problem
Hello all, I have received a solution for my problem (reading from log) from Tom Kinzer. The code is: #!/usr/bin/perl -w use strict; my $log_file = "/appl/log/4e4d/20031130.txt"; open LOG, "< $log_file" or die "Could not open file $!"; while ( ) { chomp; if ( /^GTotal Content:/ ) { my ($gtotal_content, $value) = split(/:/, $_); print $value; } } close LOG; The problem is this code returns no value. When I remove all preceding lines from the log (20031130.txt) and keep there only that GTotal Content: 14,741,322, I will get desired result (14,741,322) What may be a solution for this? Thank you for your time. danield -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
Reading from log
Hello all, I am looking for help with creating a digest of a log file. I have found a nice tutorial that should help on http://www.pageresource.com/cgirec/ptut14.htm. However, this tutorial expects to have values in list separated by | : he Rock|Cheer|Rock Bottom Triple H|Boo|Pedigree Stone Cold|Cheer|Stone Cold Stunner And I do have a log file, that looks like: ... Format count a 100 b51 c 130 d 5 e 6 Total: --- 292 ... And I need to go through that log and find that 292 and store it into variable. If it was something like 'total: 292', I might be able to do it, however the value is on completely new line and nothing precedes it. Is anyone willing to help me? I am a completely newbie in programming. Thank you for your time. danield -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>