bash: lines of a file in reverse order?

Chris F.A. Johnson cfaj-uVmiyxGBW52XDw4h08c5KA at public.gmane.org
Thu Aug 24 22:23:46 UTC 2006


On Thu, 24 Aug 2006, Interlug wrote:

> How do I return the contents of a file in reverse order, by line?
>
> I have
>
> Line 1
> Line 2
> Line 3
>
> I want it to come back as
>
> Line 3
> Line 2
> Line 1
>
> I was hoping tail -r would do it, but this appears to be a tail under
> OSX thing.
> http://www.ss64.com/osx/tail.html
>
> rev doesn't do it.
>
> $ rev < lines
> 1 eniL
> 2 eniL
> 3 eniL

    Use tac:

tac filename

> I want to find the "last matching line" in a large log file.  My hope
> was:
>
> tail -50 -r filename | grep -m 1 "matching"
> would grab it for me if it exists in the last 50 lines of the log.

grep "PATTERN" filename | tail -n1

-- 
    Chris F.A. Johnson                      <http://cfaj.freeshell.org>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list