For Loop iterations


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting For Loop iterations
# 1  
Old 07-05-2006
For Loop iterations

I have a silly beginners question here:

I'm running a for loop within an awk command as follows, however the loop only runs once, instead of 2 through to 11 and then terminating. As the output to screen of x (line 6) shows x to equal 12, when it should be 1.

---------------------------
awk ‘
for (x=2 && y=0;x<=11;x++);
if (substr($1,x,1)=="abc network") newarray[y]="a";
else newarray[y]="n/a";
y++
print “x is ” x
}' wfileperms
---------------------------

can anyone elaborate where I've gone wrong here?
Thanks
# 2  
Old 07-05-2006
Code:
awk `{
for (x=2 , y=0;x<=11;x++) {
    if (substr($1,x,1)=="abc network") newarray[y]="a";
    else newarray[y]="n/a";
    y++
   print “x is ” x 
   }
}'  wfileperms

I can only guess at your logic - added {} and changed the for() command.
# 3  
Old 07-05-2006
Quote:
Originally Posted by jim mcnamara
Code:
awk `{
for (x=2 , y=0;x<=11;x++) {
    if (substr($1,x,1)=="abc network") newarray[y]="a";
    else newarray[y]="n/a";
    y++
   print “x is ” x 
   }
}'  wfileperms

I can only guess at your logic - added {} and changed the for() command.
Thanks Jim, just the inclusion of {} around the 'for' makes the statement run correctly now.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Store 'for' loop iterations in memory

hi all, I'm writting a simple bash script to do a recursive paste over >10000 files with two columns each. The files looks like this: A1BG 3 A1CF 3 A2M 3 A4GALT 5 AAAS 2 AACS 2 AADAT 2 AAGAB 4 AAK1 3 AAMP 2 AANAT 3 AARS 2 AARS2 3 AARSD1 ... (1 Reply)
Discussion started by: lsantome
1 Replies

2. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

3. Shell Programming and Scripting

Display no. of iterations

Hello.. I have a input file as follows 123,sl 345,ab 345,cd 123,qw 123,lk I want output file as follows.. --> print the no. of iterations at the end of each row. 123,sl 1 123.qw 2 123,lk 3 345,ab 1 345,cd 2 Thanks Suresh (3 Replies)
Discussion started by: suresh3566
3 Replies

4. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

5. UNIX for Dummies Questions & Answers

how to append into single file for multiple iterations

hi, i want to capture the CPU performance, memory , harddisk usage into a single file for every 10 seconds iterations and it shall run until i kill it. can somebody plz help me in this... thanx (1 Reply)
Discussion started by: bskumar4u
1 Replies

6. Shell Programming and Scripting

How do I read several files and track "wc -l" Every 1min X 4 Iterations

I need help with these requirement: I have a FILE1, single column with list of filenames (about 30-150). I need to read each line from FILE1, do a word-count-lines of the filenames and echo a message if word-count-lines is same for 1minute X 4 iterations Example and idea below: FILE1:... (4 Replies)
Discussion started by: olu
4 Replies

7. UNIX for Dummies Questions & Answers

Process getting terminated after sleep iterations

Hello All, I have a script which has a functionality to sleep for 300 seconds after it does some processing, so in the logs if i check after the 3 iteration of sleep it didn't write saying "sleeping for 300 seconds". I suspect putty would automatically terminate session as i cannot access it any... (1 Reply)
Discussion started by: Ariean
1 Replies

8. Shell Programming and Scripting

For loop scp transfers check if all iterations successful

All, I am using a for loop to SCP a bunch of files in a directory. I am having it then drop a .ready file name. Is there a way to check for the success of all iterations and then email upon fail or success? Example of part of my script: for file in $ORIGLOC/* do ] &&... (2 Replies)
Discussion started by: markdjones82
2 Replies

9. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies
Login or Register to Ask a Question