Re: "Tailing" grep (Was: cat and grep without destroying file)




On Sun, 2007-09-30 at 19:37 -0500, Brian Fahrlander wrote:
Joel Goguen wrote:
On Sun, 2007-09-30 at 17:04 -0500, Brian Fahrlander wrote:
While we've got the attention of the most-able on this subject, I'd
like to reopen a discussion about a very similar tool: a 'grep' that
happens on tailing a file. There have been dozens of times that I'm
looking for a message number in /var/log/mail.log and would love to see
only the lines mentioning that message.

A couple of years ago I asked and got a "maybe you could write
something", but I actually never could. It's not as easy as it looks.

Any chance you guys have seen this done?

I have a great deal of success with 'tail -f /var/log/mail.log | grep
XX' where XX is whatever you're looking for. I actually use that exact
set of commands on a daily basis when I'm at work.

Wow; that's strange- am I dreaming, or is that a different
behaviour than before?

I don't know if it's different from any previous version, but it makes
perfect sense to me that it would work this way. 'tail' sends its
output to the standard output stream, which I'm piping through to
'grep'. If I don't give a file to 'grep' (which would be the second
parameter that isn't there in this example) it listens on its standard
input stream for input instead of reading a file, and here the standard
input stream is being redirected to be the output from from 'tail'.
'grep' will listen until the standard input stream closes, which it
doesn't until it encounters a 'Ctrl+D' character, 'tail' exits, or you
press Ctrl+C to stop execution.

Of course, this halts execution of a script until 'grep' exits, so it's
not useful if you want to run it in a script. You could background it I
suppose...

--
Joel Goguen
http://jgoguen.net/
The human mind treats a new idea the way the body treats a strange
protein -- it rejects it. -- P. Medawar

Attachment: signature.asc
Description: This is a digitally signed message part

--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users


Relevant Pages

  • Re: Novell Desktop Linux 10: getting closer to a toss up between Linux & Windows?
    ... On the other hand Linux has a well known (and sort of (almost) standardized ... But /video has become a sort of standard I think. ... I use 'locate' and 'grep' many times a day. ... As you have discovered finding something across many disk and partitions with so many giga bytes ...
    (comp.sys.ibm.pc.hardware.chips)
  • Re: Suffix allowed on expressions?
    ... integer can be typecasted to a pointer and the result ... text version of the C standard and grep. ... the word "typecast" appears nowhere in the standard. ...
    (comp.lang.c)
  • Re: Grep
    ... same request I get the sent mail file containing Gamblesby in the message ... What am I doing wrong with grep please? ... not a standard part of any distro. ...
    (uk.comp.os.linux)
  • Re: [Hebrew] dagesh qal - special case question
    ... Standard (i.e., non-MS) regular expressions? ... hence quite similar to sed or grep. ... Prev by Date: ...
    (sci.lang)
  • Re: Find a line in a text file then print a field
    ... Here is "grep" part of my perl script so far (ommitting the various ... the matching lines in an array. ...
    (perl.beginners)