Thread: Grep

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    20

    Grep

    Hi

    I have two questions about grep.

    1) Is grep support real time analysis ? What I mean ? I have an application that produces records continuously in a file. I try to run grep but grep run faster my application , it find my requested pattern and exits, but my application still produces records. Is there any way for grep to run continuously and produces results while my application running and produce new records ?

    2) Can grep show me only the newest pattern that it finds. For example for a file

    aaa1
    aaa2
    aaa3

    and

    > grep aaa filename

    to show me first the aaa1 , then only the aaa2 and then only aaa3

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You could try
    Code:
    tail -f filename | grep aaa
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    20
    Ok

    It is working . However sometime my application finishes ( stop produce records ) but tail still try to retrieve data from file. I put an fclose ( C programming ) function in my application to close the file but the problem remains . So how I terminate tail ( without use keyboard an Control + c ) ?

    Thanks

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well if your program wrote to stdout instead of a file, then it would simply be

    myprog | grep aaa

    Then grep would exit when your program exited.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. programming with grep
    By George2 in forum Tech Board
    Replies: 4
    Last Post: 11-18-2006, 03:30 AM
  2. simple grep problem
    By cdave in forum Windows Programming
    Replies: 7
    Last Post: 12-29-2005, 05:48 PM
  3. Grep Last Pattern Output
    By cfriend in forum Linux Programming
    Replies: 1
    Last Post: 09-18-2004, 10:14 AM
  4. Grep
    By Adam in forum C Programming
    Replies: 0
    Last Post: 06-07-2002, 06:06 AM
  5. grep
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-26-2002, 12:11 PM