For loop/while condition - doubt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For loop/while condition - doubt
# 1  
Old 12-01-2015
For loop/while condition - doubt

hi.,

As we know that using for-loop or while condition, we can only process one by one sequentially[according to provided input details], but , lets say this example :

1. under the folder "logs" there are 1000 files
2. each file has one record or line
3. have to perform atleast 7 queries per 3 seconds ,for instance
parse and process 7 files [each file has 1 record] in every three seconds

Can any one please share on how to do this shell or perl or python way.
# 2  
Old 12-01-2015
What do you mean by queries? How long would every single "query" take? On this depends the duration of processing each file. Post way more details on your request!

Normally, unless the system is HEAVILY loaded, processing 7 files in 3 seconds should be very doable.
# 3  
Old 12-01-2015
"Queries" - i meant to execute the command ..this is an example :

there are bunch of files like abc1 to abc1000
and
in first iteration:
command1 abc1
command1 abc2
command1 abc3
command1 abc4
command1 abc5
command1 abc6
command1 abc7
sleep 3
second iteration:
command1 abc8
command1 abc9
command1 abc10
command1 abc11
command1 abc12
command1 abc13
command1 abc14
sleep 3
third iteration...
and so on...yes, the system is suited to handle heavy load by means of using clustered environment.
# 4  
Old 12-01-2015
What's your shell version? With a recent bash, try:
Code:
for FN in abc*; do ((++CNT % 7 )) || sleep 3; echo $FN; done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Doubt in For loop

Hi All, I wrote a for loop where i am trying to delete the 1st line of each file and append then into a single file, my code looks like this but i am not sure if its right or worng . Can any one correct me if i am worng. FILES=path/to/files/date_*.csv for f in $FILES do sed '1d' >>... (7 Replies)
Discussion started by: vikatakavi
7 Replies

2. Shell Programming and Scripting

While Loop with if else condition

Hi, I was trying to write a shell script which reads csv file and sends mail in html format along with tables. Hope i have completed 1st part , but while sending mail i was trying to highlight some rows in the table based on the egrep outcome. If the string exists in line/INPUT, i am trying to... (4 Replies)
Discussion started by: varmas424
4 Replies

3. Shell Programming and Scripting

Case loop condition

hello, I would like to do exit at the end ie list all errors before exiting How to put the token exit in a variable with a loop ? Thanks function g1 () { case "$1" in (-0-0 | -0-1 | -0-2 | -0-3 | -1-0 | -1-1 | -1-2 | -1-3) # nothing, OK ! ;; (*) echo 'Fatal, $1 = '"'$1'"', Date... (9 Replies)
Discussion started by: amazigh42
9 Replies

4. Shell Programming and Scripting

Use of -z in while loop condition

Hi, Could you please tell what is the meaning of -z in while loop condition. For example, while ; do echo "*** Enter the age " readage (3 Replies)
Discussion started by: vidyaj
3 Replies

5. Shell Programming and Scripting

if condition in a while loop

Gurus, I need to read a line from a file and strip the characters from it and compare the stripped value with the value I pass to the script while executing it. Below is the code for the same. But when i execute the code, it is throwing an error. #!/bin/ksh . /home/.i_env ... (14 Replies)
Discussion started by: svajhala
14 Replies

6. Shell Programming and Scripting

issues with a condition in a while loop

Hi, I am facing issues with test condition. I had a compound condition to write for both if and while, In one of the texts i referred, with a korn shell we can write compound statements like: ], however this doesn't worked for me. For example: if ] doesn't works, but if || worked. ... (1 Reply)
Discussion started by: amritps
1 Replies

7. Shell Programming and Scripting

condition inside a for loop

I have a for loop in my script as shown below. for file_path in $file_list ; do ........my code .......... ...... done Can i restrict the number of files parsing to the variable file_path as 50? That is, even if I have some 100 files in file_list, I need to take only 50 files for... (7 Replies)
Discussion started by: Vijay06
7 Replies

8. Shell Programming and Scripting

IF condition doubt

Hi i found the following code in a date calculation script. if ((!(year%100))); then ((!(year%400))) && leap=1 else ((!(year%4))) && leap=1 fi I have not find such an use of if statement till now. As for my knowledge this is the syntax of if statement if then ... (1 Reply)
Discussion started by: ravi raj kumar
1 Replies

9. UNIX for Dummies Questions & Answers

What condition to be put in the while loop?

i have got a file where the env command is appended 5 times. i have to now look for the username and display it in the form of 1) PWD=/home/lee.ballancore 2) USER=lee.ballancore 3) MAIL=/var/spool/mail/lee.ballancore 4) LOGNAME=lee.ballancore 5) HOME=/home/lee.ballancore 6)... (1 Reply)
Discussion started by: nehaquick
1 Replies

10. Shell Programming and Scripting

Condition test ( [[ ]] ) doubt

Hi , I have a doubt on condition test ( ] ). Pls refer blow program. #!/bin/ksh TEMP= if ;then echo $TEMP else print 'invalid option' fi Above script's TEMP variable has no value so it gives "invalid option" as output. But I got an error before priting the string . Result : ... (2 Replies)
Discussion started by: thambi
2 Replies
Login or Register to Ask a Question