Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Dealing with Empty files, AWK and Loops Post 302652227 by A-V on Wednesday 6th of June 2012 06:13:22 PM
Old 06-06-2012
Thank you very much for your help and your time

I have learned a lot and sorry if I wasn't clear enough as I dont know what needs to happen sometimes either.

this type of coding seems very professional and easy to read so I hope I will be able to write my own next time.
and it is quite interesting how it deals with empty files


thanks again for all the help
A-V
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While loops and awk

I am trying to make a script that will replace backslashes in a file, but only if the occurance is a pathname. In the file, there are a lot of regular expressions as well, so I'm trying to preserve the integrity of those regular expressions, but convert Windows relative paths. I'm using bash and... (1 Reply)
Discussion started by: Loriel
1 Replies

2. Shell Programming and Scripting

perl: When dealing with files that do not exist

I have a process run weekly where I must convert data formats for about thirty files. I read a text file that provides all of the filenames and switch settings. My perl code is: for ($j = 1; $j <= $k; $j++) { open(FIN2,$fin2) || die "open: $!"; do other stuff } Every once in... (2 Replies)
Discussion started by: joeyg
2 Replies

3. Shell Programming and Scripting

Dealing with log files

Hi , My requirement is that i need to search for a number of strings in a log file and print them with line numbers.The search should be date wise. The sample log file is : Jan 17 02:45:34 srim6165 MQSIv500: (UKBRKR1P_B.LZ_ BENCHMARKS)BIP2648E: Message backed out to a queue; node... (6 Replies)
Discussion started by: charudpss
6 Replies

4. Shell Programming and Scripting

Dealing with files with spaces in the name

Hello, I'm a computer science major and I'm having problems dealing with file names with spaces in them. Particularly I'm saving a file name in a variable and then using the variable in a compare function i.e. a='te xt.txt' b='file2.txt' cmp $a $b If anyone could help me with this particular... (10 Replies)
Discussion started by: jakethegreycat
10 Replies

5. Shell Programming and Scripting

Iterating over subdirectories and dealing with files within them

Hello, I am working on a coding project for a class and to test the program I have created, I have come up with 100 different test cases. The program takes four text files as input, so each of the test cases is contained in a folder with four files. I have a folder called 'tests', within which... (1 Reply)
Discussion started by: dpryor
1 Replies

6. UNIX Desktop Questions & Answers

awk using 2 input files instead of while loops

Hi Friends, I have two files as input with data that looks like this: file1.txt 1 2 3 4 file2.txt a,aa b,bb c,cc d,dd e,ee f,ff instead of me doing 2 while loops to get the combinations while read line_file1 (2 Replies)
Discussion started by: kokoro
2 Replies

7. UNIX for Dummies Questions & Answers

Dealing with Double Loops, Arrays and GREP

Can someone please help me to learn how to deal with loops, arrays and grep? I have two arrays (lets say I and j) each in a separate file And have file with lines of data I need to extract, such as Ruby Smith: some text here Ruby Smith: some other text here Ruby Brown: some text here Ruby... (10 Replies)
Discussion started by: A-V
10 Replies

8. Shell Programming and Scripting

Dealing with multiple files

Korn Shell I have hundreds of small files like below created every day. A midnight cron job moves them to the location /u04/temp/logs But sometimes I have to manually move these files based a certain dates or time. I have two basic requirements 1.Using mv command I want to move all .dat... (2 Replies)
Discussion started by: kraljic
2 Replies

9. Shell Programming and Scripting

Awk: Dealing with whitespace in associative array indicies

Is there a reliable way to deal with whitespace in array indicies? I am trying to annotate fails in a database using a table of known fails. In a begin block I have code like this: # Read in Known Fail List getline < "'"$failListFile"'"; getline < "'"$failListFile"'"; getline <... (6 Replies)
Discussion started by: Michael Stora
6 Replies

10. Shell Programming and Scripting

Check file from multiple files is empty using awk

I am passing multiple files in awk & since one of the file is empty(say file3) so the same gets skipped & logic goes for toss. Need suggestion/help in checking and putting additional checks for the same awk -F, 'FNR==1 {++filecounter} filecounter==1 {KRL=$2;next} filecounter==2... (8 Replies)
Discussion started by: siramitsharma
8 Replies
RateLimiter(3pm)					User Contributed Perl Documentation					  RateLimiter(3pm)

NAME
Schedule::RateLimiter - prevent events from happening too quickly. SYNOPSIS
use Schedule::RateLimiter; # Don't let this event happen more than 5 times in a 60 second period. my $throttle = Schedule::RateLimiter->new ( iterations => 5, seconds => 60 ); # Cycle forever, but not too fast. while ( 1 ) { $throttle->event(); &do_something; } DESCRIPTION
This module provides a way to voluntarily restrict how many times a given action may take place within a specified time frame. Such a tool may be useful if you have written something which periodically polls some public resource and want to ensure that you do not overburden that resource with too many requests. Initially, one might think that solving this problem would be as simple as sleeping for the number of seconds divided by the number of iterations in between each event. However, that would only be correct if the event took no time at all. If you know exactly how much time each event is going to take then you could build an even more complicated one-liner such as this: sleep( (seconds / iterations) - single_event_time ) This module is intended to address the other cases when the exact run-time of each event is unknown and variable. This module will try very hard to allow an event to happen as many times as possible without exceeding the specified bounds. For example, suppose you want to write something that checks an 'incoming' directory once a minute for files and then does something with those files if it finds any. If it takes you two seconds to process those files, then you want to wait 58 seconds before polling the directory again. If it takes 30 seconds to process those files, then you only want to wait 30 seconds. And if it takes 3 minutes, then you want to poll the directory again immediately as soon as you are done. my $throttle = Schedule::RateLimiter->new ( seconds => 60 ); &poll_and_process while ( $throttle->event ); METHODS
" new() " Creates and returns a new Schedule::RateLimiter object. The constructor takes up to three parameters: o block (default: true) This parameter accepts a true or false value to set the default "block" behavior on future calls to event(). It makes it more convenient to turn blocking off for an entire object at a time. o iterations (default: 1) This specifies the number of times an event may take place within the given time period. This must be a positive, non-zero integer. o seconds (required) This specifies the minimum number of seconds that must transpire before we will allow (iterations + 1) events to happen. A value of 0 disables throttling. You may specify fractional time periods. example: my $throttle = Schedule::RateLimiter->new ( iterations => 2, seconds => 10 ); # Event 1 $throttle->event(); # Event 2 $throttle->event(); # Event 3 $throttle->event(); # 10 seconds will have transpired since event 1 at this point. # Event 4 $throttle->event(); # 10 seconds will have transpired since event 2 at this point. " event() " Called to signal the beginning of an event. This method will return true or false to indicate if it is ok to proceed with the event. This method uses Time::HiRes to do its calculations and sleeping, so the precision of this method will be the same as the precision of Time::HiRes on your platform. Takes one (optional) parameter: o block (default: true) If set to a false value, this method will do a non-blocking check to see if it is ok for the event to occur. If it is not ok, this method will return a false value and assume that the event did not take place. Otherwise, this method will return a true value and assume that the event did take place. example: # Stop when the code moves too fast. while ( 1 ) { if ($throttle->event( block => 0 )) { &do_something; } else { die 'I went too fast!'; } } BUGS
This module needs to keep a record of when every iteration took place, so if you are allowing a large number of iterations to happen in the given time period, this could potentially use a lot of memory. KNOWN ISSUES
If you have multiple iterations that typically happen very quickly, and you want to limit them in a long period of time, they will "clump" together. That is, they all happen at just about the same time, and then the system waits for a long period before doing the same "clump" again. That's just the nature of the best-fit algorithm. Anything that is done to try to separate single events with longer waits than necessary will potentially create a sub-optimal situation if an event in the future takes longer than expected. If you really want all of your events to start at even time periods apart from each other, then set the number of iterations to 1 and adjust the number of seconds accordingly. AUTHOR
Daniel J. Wright, <wright@pair.com> SEE ALSO
The POE module provides a more heavyweight solution to this problem as well. perl. perl v5.10.0 2003-12-04 RateLimiter(3pm)
All times are GMT -4. The time now is 11:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy