[Discuss] [vlug] How to use grep to find out very first occurrence of a pattern from last ?

J.Bakshi bakshi12 at gmail.com
Thu Jan 21 00:48:47 PST 2010


Dear list,

I am trying to do some grep searching which can find out the pattern
BUT the very first occurrence from the last ( strange no : |) )

Ok, here is an example.

---- myfile -------
some text

name = 1st name
name = 2nd name
name = 3rd name

some text
--------------------------

What I am doing presently is

grep -w "name"  myfile   and   getting     *name = 1st name*

And I need the last one ( first from the end )  which is  *name = 3rd
name*. IS it possible to use grep in this very scenario ?
piping through *sort* is not helpful here

Thanks


More information about the Discuss mailing list