For Loop inside For loop

I am new to unix and trying to make a script for writing all my command into another file and use that file to run all commands

I am trying to use for loop with echo command to generate a command based script for writing the file with all the command sequentially w.r.t for loop.

I want something like this

for i in (1..100000)
do
  for k in (1..3)
    echo "copy table_name from path " delimiter '|' on Vnode(k)
  done

.
( I am very bad with unix)

I want to use a for loop inside a for loop beacause I want value of i should always increament by 1 but the value o k should increament till 3 and again start by 1

Please help me.

You need another "done" (edit: and another "do"). A variable like i and k, need a $-sign in front of them to reference them

Thanks for the help

The code is working fine but now I have file with list of File names inside it. I want to assign the files names in place of paths keyword in the below code. Please help me.

for i in (1..100000)
do
  for k in (1..3)
    echo "copy table_name from <filenames> " delimiter '|' on Vnode(k)
  done 

How do i get the different file names in here?

Please post some sample from the content of file and the desired output

I don't see a 'paths keyword' in your code. Assuming that you have your list of file names in a file called filename-file and that your target systems are something 1 through 3, then you could use something along these lines:

#!/usr/bin/env ksh
while read filename
do
    for (( k = 1; k < 4; k++ ))
    do
        echo "copy $filename to node($k)"
    done
done <filename-file

This reads each file from filename-file into the variable filename (assuming one per line) and then will write three copy lines per file to the standard output. I assume you'd replace the echo with the actual command to copy the file to the remote node.

This should also work in bash should you prefer that shell.

Hope this at least gets you started.

Hello ,

I dnt want three copy commands for each file, instead i want one copy line for each file with node 1 and then another copy command with next file and node 2 and then another copy command with next file and node 3. from here on it again comes up with next file name but the node number starts with 1 again and then next file and node 2, next file node3 again next file node1

I want something like this:

copy table_name from <fileaa.txt>  on node1
copy table_name from <fileab.txt> on node2
copy table_name from <fileac.txt>  on node3
 copy table_name from <filesd.txt> on node1
copy table_name from <fileaa.txt>  on node2
copy table_name from <filean.txt> on node3
copy table_name from <filetr.txt> on node 1
.
.
.
.
.

I have around 100000 such coppy command on which i want this pattern. Please help me with this

Try:

k=-1
while read file; do
  echo "copy $file to node($(((k+=1)%3+1)))"
done < infile