bash: lines of a file in reverse order?
Scott Elcomb
psema4-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Fri Aug 25 03:13:06 UTC 2006
On 8/24/06, Gregory D Hough <mr6re9-mI4xJ4qlgtBiLUuM0BA3LQ at public.gmane.org> wrote:
> > 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
> >
> A
> #!/bin/bash
> grep "INVALID" /var/log/messages | tail -n1
>
> time sh A
> Aug 24 15:52:22 localhost kernel: INVALID: IN=eth1 OUT= SRC=69.63.65.165
>
> real 0m0.044s
> user 0m0.001s
> sys 0m0.015s
>
>
> B
> #!/bin/bash
> tail -50 /var/log/messages | tac | grep -m1 "INVALID"
>
> time sh B
> Aug 24 15:52:22 localhost kernel: INVALID: IN=eth1 OUT= SRC=69.63.65.165
>
> real 0m0.048s
> user 0m0.004s
> sys 0m0.016s
>
> Yep, method A is 4 to 5 thou faster than B most of the time
That's kinda cool. Might get more accuracy on the last statment if
others' results were averaged in.
Still, that's a really interesting test, thanks for the results. Is
there a way to track memory usage during the same periods?
--
Scott Elcomb
http://atomos.sourceforge.net/
http://search.cpan.org/~selcomb/SAL-3.03/
http://psema4.googlepages.com/
"In matters of style, swim with the current; in matters of principle,
stand like a rock."
- Thomas Jefferson
--
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