Grep

This is a discussion on Grep within the Linux Programming forums, part of the Platform Specific Boards category; Hi I have two questions about grep. 1) Is grep support real time analysis ? What I mean ? I ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02:30 AM
  2. simple grep problem
    By cdave in forum Windows Programming
    Replies: 7
    Last Post: 12-29-2005, 04: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, 11:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21