Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 16th, 2004, 10:37 AM   #1
cfriend
Newbie
 
Join Date: Jul 2004
Posts: 8
Rep Power: 0 cfriend is on a distinguished road
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
cfriend is offline   Reply With Quote
Old Sep 16th, 2004, 10:59 AM   #2
Ashcroft
Programmer
 
Join Date: Sep 2004
Posts: 38
Rep Power: 0 Ashcroft is on a distinguished road
Grep is not really appropriate for realtime analysis of a logfile, look for 'swatch' for a daemon that handles this.

If I understand your second question you want unique matches. The usual way to do this in the shell is to use sort and uniq.

$ grep aaa file | sort | uniq
Ashcroft is offline   Reply With Quote
Old Sep 16th, 2004, 11:16 PM   #3
erebus
Programmer
 
erebus's Avatar
 
Join Date: Aug 2004
Location: /dev/null
Posts: 65
Rep Power: 5 erebus is on a distinguished road
Send a message via AIM to erebus
In that perticular instance, this would be a little bit more effcient:
$ grep aaa file | sort -u
__________________
<span style='font-size:14pt;line-height:100%'><span style='color:red'>&quot;Political power grows out of the barrel of a gun&quot; - Mao Tse-Tung</span></span>
erebus is offline   Reply With Quote
Old Sep 17th, 2004, 3:57 AM   #4
Ashcroft
Programmer
 
Join Date: Sep 2004
Posts: 38
Rep Power: 0 Ashcroft is on a distinguished road
Yeah thats true, I always forget about that -u arg to sort and avoiding an extra process can be very important if the file you grep is huge.
Ashcroft is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC