Re: Reading Log
- From: Stephane CHAZELAS <stephane_chazelas@xxxxxxxx>
- Date: Tue, 10 Jun 2008 16:33:17 +0000 (UTC)
2008-06-10, 18:17(+02), Marcel Bruinsma:
[...]Anyway, I was thinking, is there a way to do a "grep" that starts at
the end of file and STOPS on the first match ? So they could add as
many lines they wanted.
tac log.log | sed '/xyz/!d;q' | cut ...
However, tac doesn't really start at the end of the file,
it reads lines from beginning to end, like tail. It just
prints output from end to begin.
You might as well skip tac:
sed '/xyz/!{$!d;g;q};$q;h;d' log.log | cut ...
ITYM: sed '/xyz/!{H;$!d;g;};$q;h;d'
or: sed '/xyz/{$q;h;d;};H;$!d;g'
which assumes the file does contain the pattern
Note that many sed implementations have a limited hold or
pattern space size (IIRC, POSIX requires it to hold at least 10
lines), so the above will not necessarily be very reliable
(there's a missing ";" after the first q BTW).
Also tac (see also tail -r on some systems) does read from the
end (by doing lseeks), so for big files, it will be more
efficient.
--
Stéphane
.
- Follow-Ups:
- Re: Reading Log
- From: Marcel Bruinsma
- Re: Reading Log
- References:
- Reading Log
- From: Jl_G_0
- Re: Reading Log
- From: Marcel Bruinsma
- Re: Reading Log
- From: Marcel Bruinsma
- Reading Log
- Prev by Date: Re: Reading Log
- Next by Date: Re: Reading Log
- Previous by thread: Re: Reading Log
- Next by thread: Re: Reading Log
- Index(es):
Relevant Pages
|