![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 Lestat |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
tail -f -s5 ?
|
|
#3
|
||||
|
||||
|
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
|
|
#4
|
||||
|
||||
|
pixelbeat it still dont work, 'tail -f -s5 file1 works' but not just 5 seconds, it works like 'tail -f file1'
|
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
but that doesn't preclude the op from checking every 5 seconds if he wished ...
|
|
#7
|
||||
|
||||
|
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) |
||||
| Google The UNIX and Linux Forums |