Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: print a file from Bottom to Top (reverse order)

by theravadamonk (Scribe)
on Jun 20, 2018 at 18:29 UTC ( [id://1217037]=note: print w/replies, xml ) Need Help??


in reply to Re: print a file from Bottom to Top (reverse order)
in thread print a file from Bottom to Top (reverse order)

Thank you very much for your code. it works as expected. my file is actually maillog file. It's sometimes huge. So File::ReadBackwards is much better. But, the problem is I am trying to insert below lines in to that code.

if (/Passed CLEAN/) { #search string Passed CLEAN print "$_ \n"; # print ALL lines containing Passed CLEAN }

But, still no success. I am learning perl. I am still a novice. I googled how to insert it, But, still not lucky.

Replies are listed 'Best First'.
Re^3: print a file from Bottom to Top (reverse order)
by Laurent_R (Canon) on Jun 20, 2018 at 18:45 UTC
    Changing just a couple of small things to haukex's solution above should give you what you need:
    use warnings; use strict; use File::ReadBackwards; my $bw = File::ReadBackwards->new('/var/log/maillog') or die $!; while (defined( my $line = $bw->readline )) { print $line if $line =~ /Passed CLEAN/; } $bw->close;

      Thanks a lot for your kind reply. I get what I expect from your INPUT. I thank all who participated in this mail tread.

Re^3: print a file from Bottom to Top (reverse order)
by AnomalousMonk (Archbishop) on Jun 20, 2018 at 19:04 UTC

    Given Laurent_R's comprehensive reply, let's move on to the next question: How do I match one or more arbitrary whitespace characters between the  'Passed' and the  'CLEAN' in the pattern match? Please see the  + quantifier in perlre, and  \s in perlre and Whitespace in perlrecharclass. In general, please see perlretut.


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1217037]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found