bash: lines of a file in reverse order?

Interlug interlug-vSRlqIl1h/9eoWH0uzbU5w at public.gmane.org
Thu Aug 24 18:29:09 UTC 2006


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? 

--
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