On Mon, 2006-05-06 at 08:51 +0800, joseph wrote: > Hello List, > > I need help in extracting a range of lines from a log files, i tried to do > it with this script: > > > #!/bin/perl > > use strict; > use warnings; > > open(FILE,"/home/teragram/status_log.txt") or die "can't open file $!\n"; > my @line; > > while (<FILE>) { > if (/DATE:\s\d.*/../END_TIME:\s\d.*/) ##This line taken from sample > solution on perl cookbook, but I doubt if i did it right what the author > mean.### > { > push @line,$_; > } > } > > my $popped = pop @line; > print "\t $popped \n"; > > > ### Here the format of logfiles#### > > > DATE: 2003/7/26 > > START_TIME: 1:5:13 > New Update files: > /home/teragram/daily_cycle/updates/headingupdates2003-07-24-16-00.xml > Applying update: > /home/teragram/daily_cycle/updates/headingupdates2003-07-24-16-00.xml > Updated /home/teragram/daily_cycle/data/marc_info.txt > Updated /home/teragram/daily_cycle/data/use_info.txt > Admin files updated > Updated /home/teragram/daily_cycle/data/search_master_file.txt > Updated /home/teragram/daily_cycle/bindata/admin.ha > /home/teragram/daily_cycle/bindata/marc_info.cm updated > /home/teragram/daily_cycle/bindata/use_info.cm updated > Updated /home/teragram/daily_cycle/bindata/headings.hm > Updated /home/teragram/daily_cycle/bindata/search.min.aut and > /home/teragram/daily_cycle/bindata/search.cm > Updated /home/teragram/daily_cycle/bindata/search.alph, > /home/teragram/daily_cycle/bindata/search.idx and /home/teragram/dail > y_cycle/bindata/search.td > END_TIME: 7:13:30 > > DATE: 2003/7/27 > > START_TIME: 1:13:35 > No Updates found > No updates found > END_TIME: 1:13:46 > > DATE: 2003/7/28 > > START_TIME: 1:13:52 > No Updates found > No updates found > END_TIME: 1:14:3 > > Now, I need too accmplished these: > > 1.Get the text from DATE/format/here to END_TIME/format/here. > 2.Get only the latest one or the end portion since this log append the > previous date logs. > > with my script above I got only the END_TIME/format/here section, I've tried > also reading it by paragraph but to no avail, is there any modules or tricks > to do the job? > > As always.thanks a lot. > > /joseph
Do you want the last set of lines from DATE... to END TIME...? while(<FILE>){ @line = () if /^DATE:/; push @line, $_; } print @line; -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>