Get lines in 5 seconds


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get lines in 5 seconds
# 8  
Old 06-15-2005
Quote:
Originally Posted by Lestat
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...
... just curious --- what is the exact command line did you use to do the "wc -l"?
# 9  
Old 06-15-2005
The script is:

Code:
wc -l file1 | grep EXACTO > my_file
sleep5
wc -l file1 | grep EXACTO >> my_file

so in my_file i get the number of lines, the difference between those are what i need but it takes too much time.

any other idea?
# 10  
Old 06-15-2005
Do you have control of the process writing these logfiles? If so you could just timestamp the log entries....

Or, you could write a script that will mark the logfile every 5 seconds by adding a line that's simle to search for and contains the time...

<------- 06/15/2005 15:27:35 --------->
# 11  
Old 06-15-2005
the problem is that i cannot alter those file cuz is used to generate statistics
# 12  
Old 06-15-2005
Quote:
Originally Posted by Lestat
The script is:

Code:
wc -l file1 | grep EXACTO > my_file
sleep5
wc -l file1 | grep EXACTO >> my_file

so in my_file i get the number of lines, the difference between those are what i need but it takes too much time.

any other idea?
the problem here is that you are re-reading the file to grep out EXACTO after you read it the first time to count how many lines it has ... if the first read takes 3 seconds, the second read will probably takes just as long if not longer even though you really only need to read it once ...

... just grep out EXACTO from file1 then do the rest of the code i put in ... try it out and let us know if it helps or not ...
Code:
grep EXACTO file1 >> file2
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

# 13  
Old 06-20-2005
It works but it is still slow... there is not a way to do it with 'tail whatever'?
# 14  
Old 06-20-2005
I did not quite understand how free are you to interfere with the file.
If you cannot catch it when it is written, may be you could pipe the output of "tail -f file1" to the program in C that would sleep for 5 secs, then print a timestamp and all lines it can read and sleep again? There still may be problems with timing mentioned by Jim M. but you may get some idea about what's going on.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sorting and wc -l w.r.t seconds

I have file with below data 00:00:00 00:00:00 00:00:00 00:00:01 00:00:01 00:00:01 00:00:01 00:00:01 00:02:01 00:02:01 00:02:01 so on till 23:59:59 I want count of seconds for each hour and minutes say for 00:00:00 its 3 and 00:00:01 its 5 and 00:02:01 its 3 and so on... (8 Replies)
Discussion started by: mirwasim
8 Replies

2. Shell Programming and Scripting

datetime difference in seconds

Hi, I'm trying to find processing time of my script. Please can someone give me the commands to get the start/end time in "dd-mm-yyyy hh:mm:ss" and the differnce in seconds. Thanks! (5 Replies)
Discussion started by: dvah
5 Replies

3. UNIX for Dummies Questions & Answers

Number of leap seconds

Is there a function call in std library or unit command that returns the number of current leap seconds? GG (4 Replies)
Discussion started by: NAVTime
4 Replies

4. Shell Programming and Scripting

How to delay the process for few seconds

Hi, In my shell script, (as per the requirement), I am creating few files, and the processes are launched parallelly . (by using "&" at the end of the command line). As per the logic, I need to remove these files as well, after creating. But, the problem is, due to parallel processing,... (3 Replies)
Discussion started by: jitendriya.dash
3 Replies

5. Shell Programming and Scripting

Convert Seconds to hh:mm:ss

Hi All I need to convert a number of fields in a record from seconds to hh:mm:ss ( or possibly hhh:mm:ss ). I'm guessing awk is the way to go . File has multiple records and each record contains 101 fields - can awk handle that ? The seconds values will be in fields 3 - 101 and could be 0. ... (4 Replies)
Discussion started by: Mudshark
4 Replies

6. HP-UX

Ticks in seconds.

Hello all, Is there any thumb rule or aproximation of the equivalence in second of one tick? Thank you in advance. (1 Reply)
Discussion started by: mig28mx
1 Replies

7. UNIX for Advanced & Expert Users

Time Difference in seconds

It is required to calculate time difference in seconds between epoch time (19700101 00:00:00) and any given date time (e.g. 20010214 14:30:30). Is there any command in unix to get it? Thanks in adv. (1 Reply)
Discussion started by: k_bijitesh
1 Replies

8. UNIX for Dummies Questions & Answers

seconds to hh:mm:ss

Any sleek way to convert seconds to hh:mm:ss format . I know it can be done by mod and divide . Looking for a one liner if possible . Example 3600 seconds = 01:00:00 3601 seconds = 01:00:01 (2 Replies)
Discussion started by: akrathi
2 Replies

9. UNIX for Advanced & Expert Users

how to get number of seconds

How do I get the number of seconds since 1970, within a script, for the previous day at 23:59? I need this value to pass into a sql statement to cleanup records older than the previous day at midnight. It will be automated via cron so no hard coding allowed. Thanks! (2 Replies)
Discussion started by: captainzeb
2 Replies
Login or Register to Ask a Question