split an action in groups


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting split an action in groups
# 1  
Old 11-11-2011
split an action in groups

Hi all,

I need some help with a script I would like to amend.Let's say it's a simple script like the one below

Code:
controls=`grep line /etc/file |grep -v "^#"| awk -F":" '{print $4}'`
for cc in $controls
do
        echo $cc
        sleep 2
done

cc variable holds a list of 40 numbers. What I would like to do is for every five cc's to do an echo and then sleep for 2 seconds, then continue to the next five. Can anyone help me out with that please?

Thanks in advance
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 11-11-2011 at 10:46 AM.. Reason: code tags, please!
# 2  
Old 11-11-2011
add a variable for count '5'
Code:
for var in $cont
do
echo $var
num=`expr $num + 1`
if [ $num -eq 5 ];then
sleep 2
num=0
fi
done

This User Gave Thanks to posix For This Post:
# 3  
Old 11-11-2011
Code:
#!/bin/ksh

typeset -i c=0
cont='a b c d e f g h i j k l'

for var in $cont
do
  echo $var
  c=$((c+1))
  (( ! (c%5) )) && sleep 2
done

This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

multiple action!

lets explain it easy by showing the initial file and desired file: I've a file such this that contains: initial_file: 31/12/2011 23:46:08 38.6762 43.689 14.16 Ml 3.1 ... (1 Reply)
Discussion started by: oreka18
1 Replies

2. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

3. Shell Programming and Scripting

Need help with find its action

I am writing a shell script that takes at least 2 arguments. The first is an octal representation of file permissions, the second is a command that is executed on all the files found with that permission. #!/bin/sh find . -perm $1 -exec $2 $3 $4 {} \; invoked: ./script.sh 543 ls -la what... (3 Replies)
Discussion started by: computethis
3 Replies

4. Shell Programming and Scripting

same action in then as in else: explanation?

in /etc/init.d/networking of an ubuntu computer, I found this code: if ifdown -a --exclude=lo; then log_action_end_msg $? else log_action_end_msg $? fi Shouldn't it be replace by ifdown -a --exclude=lo ... (0 Replies)
Discussion started by: raphinou
0 Replies

5. UNIX for Dummies Questions & Answers

Split a file with no pattern -- Split, Csplit, Awk

I have gone through all the threads in the forum and tested out different things. I am trying to split a 3GB file into multiple files. Some files are even larger than this. For example: split -l 3000000 filename.txt This is very slow and it splits the file with 3 million records in each... (10 Replies)
Discussion started by: madhunk
10 Replies

6. UNIX for Advanced & Expert Users

tracking user action

Hi, we are using solaris8. we have some files disappear. I would like to know how to track who and when the files was remove ??? thanks, (7 Replies)
Discussion started by: xitrum
7 Replies

7. Shell Programming and Scripting

action command

Hi.. When i refered the script /etc/rc.sysinit... i found the "action commands" like But this is not working in my shells.. the following error is coming... Please anybody help Thanks in advance esham (5 Replies)
Discussion started by: esham
5 Replies
Login or Register to Ask a Question