The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ticks in seconds. mig28mx HP-UX 1 06-26-2007 05:43 PM
How to count lines - ignoring blank lines and commented lines kthatch UNIX for Dummies Questions & Answers 6 05-24-2007 10:21 PM
seconds to hh:mm:ss akrathi UNIX for Dummies Questions & Answers 2 10-19-2005 11:30 AM
how to get number of seconds captainzeb UNIX for Advanced & Expert Users 2 12-02-2003 03:12 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-15-2005
Lestat's Avatar
Registered User
 

Join Date: Feb 2005
Location: Quito - Ecuador
Posts: 67
Exclamation Get lines in 5 seconds

Hello everybody, how i can get how many lines are writed in a file in the last 5 seconds?

For ezample i have 'file1' that is filled by a process automatically and i neet to know how many lines with the word 'EXACTO' were filled the last 5 seconds, can somebody help me?

I try with:

Code:
tail -f file1 | grep EXACTO > file2
but it just copy the last files to 'file2' but not in the last 5 seconds, that have sence? please your help.

Lestat
Reply With Quote
Forum Sponsor
  #2  
Old 06-15-2005
Registered User
 

Join Date: Jun 2005
Location: Ireland
Posts: 61
tail -f -s5 ?
Reply With Quote
  #3  
Old 06-15-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
try ...

Code:
currcnt=0
oldcnt=0
while true
do
    currcnt=$(wc -l file1 | awk '{print $1}')
    if [ $currcnt -ne $oldcnt ]
    then
        sed "1,${oldcnt}d" file1 | grep "EXACTO" >> file2
        oldcnt=$currcnt
    fi
    sleep 5
done
Reply With Quote
  #4  
Old 06-15-2005
Lestat's Avatar
Registered User
 

Join Date: Feb 2005
Location: Quito - Ecuador
Posts: 67
pixelbeat it still dont work, 'tail -f -s5 file1 works' but not just 5 seconds, it works like 'tail -f file1'
Reply With Quote
  #5  
Old 06-15-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
File writes do not always work the way you think they do.

Unless the process writing the file calls fflush() for every line or is using aio calls, the kernel accumulates file data in memory for a while, then writes a bunch of stuff all at once to the file. The bunch of stuff it decides to write may end somewhere in the middle of a line.

What this means is that you could wait for 20 seconds, while nothing is written to the file. Then during the 21st second, 8192 bytes of data is written to the file.
Reply With Quote
  #6  
Old 06-15-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
but that doesn't preclude the op from checking every 5 seconds if he wished ...
Reply With Quote
  #7  
Old 06-15-2005
Lestat's Avatar
Registered User
 

Join Date: Feb 2005
Location: Quito - Ecuador
Posts: 67
At first time i try to get whe num of lines actual, then the num of lines in 5 seconds then the difference between they, but in 'file1' i have thousand of lines and a 'wc -l file1' take to much time...

For Jim Mcnamara:
The file1 is filled in real time, so i dont have problem like that (i think)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0