The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-30-2008
ammu ammu is offline
Registered User
 

Join Date: Jul 2006
Posts: 62
Perl onliner to search the last line with an occurence of a pattern

Hi

I need a perl onliner which seaches a line starting with a pattern(last occurence) and display it.
similar to

grep 'pattern' filename | tail -1 in UNIX

Ex: I want to display the line starting with "cool" and which is a last occurence

adadfadafadf
adfadadf
cool dfadfadfadfara
adfadfadf
cool aaaaaaaaaaaaaa
hai how are you

It should dispaly the line which is red. I need it in perl one line command

I am not sure how i should do. I have an idea that we can do it with

perl -ne 'print .........

Your help will be highly appreciated

Thanks
Ammu
Reply With Quote
Remove advertisements
!!
Forum Sponsor