bash: lines of a file in reverse order?
James McIntosh
jemcinto-cpI+UMyWUv+w5LPnMra/2Q at public.gmane.org
Thu Aug 24 23:25:09 UTC 2006
At 02:29 PM 2006/08/24 -0400, Interlug <interlug-vSRlqIl1h/9eoWH0uzbU5w at public.gmane.org> 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
>
>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.
>
>Surely this is being done elsewhere. Got a pointer?
Yes.
Do this in two stages.
First find ALL matching lines, and pipe the results to the second stage.
Second stage is to take the very last of the piped records, by using the
programme 'tail'.
This uses a larger temporary file than your proposed solution, but it would
always work.
Jim McIntosh <jemcinto-cpI+UMyWUv+w5LPnMra/2Q at public.gmane.org>
--------------------------------------
--
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