Parallel increment of nested for loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parallel increment of nested for loop
# 1  
Old 06-20-2017
Parallel increment of nested for loop

Hi,

I am using solaris 5.10 environment and need help on doing parallel increment of nested for loop.

Samples
Code:
#inside the code the values assigned to a variable by another awk command will be like
a=/xyz/pg/as
/xyz/pg/as2
/xyz/pg/as3
b=/xyz/sd/fd1
/xyz/sd/fd2
/xyz/sd/fd3

for q in ${a[@]}; do
  for p in ${b[@]}; do
  LName=`find "$p" -name *"$x".txt -type f |sort | head -1`
  if [ "$LName" != "" ]; then		
     break
  fi
  done
  done

definitely there will be equal amount of records in both variable a & b. based on the file availability in the corresponding path in variable b, i need to choose the corresponding path from variable a.

say for example *"$x".txt file was available in the path /xyz/sd/fd3 (3rd iteration) i need to choose the corresponding path (/xyz/pg/as3) from variable a for further processing.

Code:
cFile=`find "$q" -name *.log -type f |sort | head -1`

# 2  
Old 06-20-2017
Unfortunately, you don't mention the shell version that you use. A recent one would help... This one is for bash 3+ ...
You assign data to simple variables a and b , but reference either as an array. Why not use arrays in the first place?
Code:
a=(/xyz/pg/as
/xyz/pg/as2
/xyz/pg/as3)
b=(/xyz/sd/fd1
/xyz/sd/fd2
/xyz/sd/fd3)
for i in ${!a[@]}; do echo ${a[$i]}, ${b[$i]}; done
/xyz/pg/as, /xyz/sd/fd1
/xyz/pg/as2, /xyz/sd/fd2
/xyz/pg/as3, /xyz/sd/fd3

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Batch file loop and increment value for condition

I am trying to have the below batch file do following two things: 1. only allow the values YES,yes,Y,y, or NO,no,N,n 2. increment the counter %var1 only if answer to question 2 is "y" and not able to get the syntax correct. If %var1%=1 then I am trying to display function :end. Thank you :).... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

Find and increment at each occurence of string (loop)

I created script (sh shell) to generate vlc playlist based on some data files. All works fine so far except one string I do not know how to handle with. VLCSTART='<vlc:id>' VLCV=0 VLCEND='</vlc:id>' echo -e $'\n'$'\t'$'\t'$'\t'$'\t'\$VLCSTART$VLCV$VLCENDOutput file contains several occurences... (10 Replies)
Discussion started by: TiedCone
10 Replies

3. Shell Programming and Scripting

For/While Loop to Increment Filenames in a Script

Daily stupid question. I want to increment the file name everytime the script is run. So for example if the filename is manager.log and I run the script, I want the next sequence to be manager.log1. So to be clear I only want it to increment when the script is executed. So ./script... (10 Replies)
Discussion started by: metallica1973
10 Replies

4. Shell Programming and Scripting

Nested if loop

Hi Team, I just want to check whether my nested if loop used is correct or not. if ] if ] export1 else export2 fi else if ] export3 else export4 fi fi Thanks Shiva (5 Replies)
Discussion started by: shivashankar_S
5 Replies

5. Programming

[Xquery] How to do a increment in a For loop

Hello men. How can i build a simple increment for $a by Xquery such as ? let $a := 0 for $i in (1 to 10) let $a := $a + 1 return $a why a in this loop always is '1' Thank you for reading, its will really helpful for my job if i can solve this problem :D:D (3 Replies)
Discussion started by: tien86
3 Replies

6. Shell Programming and Scripting

Increment nested for loop parllely

Hi , I am trying to increment the nested for loops parellely,but i cant ,i used continue 2 but the second loop not getting increment. no1="1 6 5 4 8" no2="4 7 8 0 1" for var1 in $no1 ; do for var2 in $no2 ; do line1 line 2 line 3 continue 2 done done Please help on this (4 Replies)
Discussion started by: nmahendran
4 Replies

7. Shell Programming and Scripting

the given code goes in infinite loop and does not increment variable i

code is as #!/bin/sh i=1; while do welcome $i times; i='expr $i+1'; done exit 0; (6 Replies)
Discussion started by: mrityunjay22
6 Replies

8. Shell Programming and Scripting

Increment date in 'for' loop?

Hi Guys, My first post..:) Right...I want to move existing files (with some date in their name) currently in $mainftp, to $mainfolder/$foldate/system1. I'd like to be able to increment date in the for loop? Is this possible or should I use a different technique. The script return the... (4 Replies)
Discussion started by: SunnyK
4 Replies

9. Shell Programming and Scripting

nested loop

I have two do loops. When I break of the inner loop it doesn't go back to the outer loop but exit the program. (5 Replies)
Discussion started by: chinog
5 Replies
Login or Register to Ask a Question