Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: how to find last word match ?

by eyepopslikeamosquito (Archbishop)
on Nov 24, 2010 at 07:38 UTC ( [id://873374]=note: print w/replies, xml ) Need Help??


in reply to Re^2: how to find last word match ?
in thread how to find last word match ?

As a Perl one-liner, from the Unix command line, that would be:

perl -ne '/Baki/ and $x=$_}{print$x' file.txt
or:
perl -ne '/Baki/ and $x=$_; END{print$x}' file.txt

Update: BTW, your shell solution:
cat file.txt |grep "Baki" |tail -1
should read:
grep 'Baki' file.txt |tail -1
Tom Christiansen once wrote long ago on usenet something like "If you find yourself calling cat with just one argument, you're probably doing something silly".

Update: See also Re: perl one liner for csv file one field (useless use of cat and other awards References)

Replies are listed 'Best First'.
Re^4: how to find last word match ?
by happy.barney (Friar) on Nov 24, 2010 at 08:08 UTC
    perl -e 'print((grep/Baki/,<>)[-1])' file.txt

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-19 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found